<p>I know this is a late reply. I hope it will help others.</p>

<p>You need to <code>return false;</code> so that the background color is red.</p>

<p>Example:</p>

<pre><code>     if (count($criteria-&gt;ids()) &gt; 1)
     {
         $this-&gt;setMessage($this-&gt;getParams()-&gt;warningMessage);

         return false;
     }
</code></pre>

CC BY-SA 3.0
2016-09-29T10:05:03.463Z
2016-09-29T17:12:42.463Z
2016-09-29T17:12:42.463Z
Anya Dit
<p>I call a service function inside the performAction method of custom element-action and I'd like to show an error message to user if the service function returned false.</p>

<p>I was able to set success message by using:</p>

<pre><code>$this-&gt;setMessage($this-&gt;getParams()-&gt;successMessage);
</code></pre>

<p>But I don't know how to set an error message i.e. with red background.</p>

<plugin-development><plugins><control-panel><elementaction>
How to set error message in element action?
# How to set error message in element action?

(Asked by: username_0 on 2016-02-06)

I call a service function inside the performAction method of custom element-action and I'd like to show an error message to user if the service function returned false.
I was able to set success message by using:
$this->setMessage($this->getParams()->successMessage);

But I don't know how to set an error message i.e. with red background.

**Tags:** plugin-development, plugins, control-panel, elementaction


---

## 1 answers

### Answer by username_1 on 2016-09-29. Score: 1 | Accepted answer

I know this is a late reply. I hope it will help others.
You need to return false; so that the background color is red.
Example:
     if (count($criteria->ids()) > 1)
     {
         $this->setMessage($this->getParams()->warningMessage);

         return false;
     }


---

