# \[SOLVED\] Help creating new automatic action

**URL:** <https://kanboard.discourse.group/t/solved-help-creating-new-automatic-action/1905>\
**Category:** Open Discussions\
**Created:** [July 20, 2021, 8:55pm UTC](https://kanboard.discourse.group/t/solved-help-creating-new-automatic-action/1905 "2021-07-20T20:55:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Capataloutchoupika](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/capataloutchoupika/32/751_2.png) [@Capataloutchoupika](https://kanboard.discourse.group/u/Capataloutchoupika)\
**Post date:** [July 20, 2021, 8:55pm UTC](https://kanboard.discourse.group/t/solved-help-creating-new-automatic-action/1905/1 "2021-07-20T20:55:27Z")

</div>

Hi everyone 🙂

I’m looking for some help to create a new automatic action based on comment.create event.  
I have no idea why my action / event is never triggered…  
Expected : move a task on specific swimlane when comment is added.

(Of course, automatic action is created from UI in my settings project :P)

Plugin.php :

```auto
$this->actionManager->register(new MoveTaskSwimlaneOnComment($this->container));
$this->eventManager->register(CommentModel::EVENT_CREATE, "Création d'un commentaire");

```

Action/MoveTaskSwimlaneOnComment.php :

```auto
<?php

namespace Kanboard\Plugin\devTestsPlugin\Action;

use Kanboard\Action\Base;
use Kanboard\Model\CommentModel;

class MoveTaskSwimlaneOnComment extends Base
{
    public function getDescription()
    {
        return t('Déplacer la tâche dans une swimlane lorsqu\'un commentaire est laissé');
    }

    public function getCompatibleEvents()
    {
        return array(
            CommentModel::EVENT_CREATE,
        );
    }

    public function getActionRequiredParameters()
    {
        return array(
            'swimlane_id' => t('Swimlane'),
        );
    }

    public function getEventRequiredParameters()
    {
        return array(
            'task_id',
        );
    }

    public function doAction(array $data)
    {
        $values = array(
            'id' => $data['task_id'],
            'swimlane_id' => $this->getParam('swimlane_id'),
        );

        return $this->taskModificationModel->update($values);
    }

    public function hasRequiredCondition(array $data)
    {
        return true;
    }
}

```

Nothing in apache logs, nothing with DEBUG, comment is created without triggering anything ☹  
If you have any idea it could be great !

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [July 21, 2021, 1:06am UTC](https://kanboard.discourse.group/t/solved-help-creating-new-automatic-action/1905/2 "2021-07-21T01:06:05Z")

</div>

check your stderr logs for php errors… I see you using a model but it’s not in the “use”.

try adding:

```auto
use Kanboard\Model\TaskModificationModel;

```

or maybe just add:

```auto
use Kanboard\Model\TaskModel;

```

I cant remeber…its been awhile for me since I’ve actually done this.

---

<div class="post-metadata">

**Author:** ![Capataloutchoupika](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/capataloutchoupika/32/751_2.png) [@Capataloutchoupika](https://kanboard.discourse.group/u/Capataloutchoupika)\
**Post date:** [July 23, 2021, 5:57pm UTC](https://kanboard.discourse.group/t/solved-help-creating-new-automatic-action/1905/3 "2021-07-23T17:57:15Z")

</div>

Hi 🙂  
I enable all levels for logging and nothing in stderr logs (apache / system / php logs) ☹ No warning, no errors.  
These “use” aren’t required (I don’t use it on my others custom Action), but I tried to add these and… nothing 😭 😭 😭

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [July 26, 2021, 2:17pm UTC](https://kanboard.discourse.group/t/solved-help-creating-new-automatic-action/1905/4 "2021-07-26T14:17:21Z")

</div>

> [@Capataloutchoupika](#):
>
> ```auto
> use Kanboard\Model\CommentModel;
> 
> ```

I played with it, and figured out the error.

change your code to:

```auto
{
    public function getDescription()
    {
        return t('Déplacer la tâche dans une swimlane lorsqu\'un commentaire est laissé');
    }

    public function getCompatibleEvents()
    {
        return array(
            CommentModel::EVENT_CREATE,
        );
    }

    public function getActionRequiredParameters()
    {
        return array(
            'swimlane_id' => t('Swimlane'),
        );
    }

    public function getEventRequiredParameters()
    {
        return array(
            'task',
        );
    }

    public function doAction(array $data)
    {
        $values = array(
            'id' => $data['task']['id'],
            'swimlane_id' => $this->getParam('swimlane_id'),
        );
        return $this->taskModificationModel->update($values);
    }

    public function hasRequiredCondition(array $data)
    {
        return true;
    }
}

```

comment event does not have `task_id`, which stopped the action.

and you were correct, there were no error messages, it simply stopped after `getEventRequiredParameters`

what i do to problem solve those no message errors, is place `error_log` messages in key areas to figure out where things stop, and then i can diagnose why. you can also use it to make sure you are getting expected results/values.

in this particular case, i placed an `error_log` in `doAction`, and because it would not trigger, i added one to the previous function, `getEventRequiredParameters`, which did trigger. That left only one possible error, the Event Parameter. Now from here, you can dive in and figure out what does exist, or does not, but I simply guessed from here, and it makes complete sense that `task_id` would not be a parameter in the comment event, so i went with what i know from previous actions using the comment event, and just changed it to `task` and adjusted accordingly.

hope that helps, sorry for my bad typing, but i am currently minus a left hand.

---

<div class="post-metadata">

**Author:** ![Capataloutchoupika](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/capataloutchoupika/32/751_2.png) [@Capataloutchoupika](https://kanboard.discourse.group/u/Capataloutchoupika)\
**Post date:** [July 26, 2021, 4:05pm UTC](https://kanboard.discourse.group/t/solved-help-creating-new-automatic-action/1905/5 "2021-07-26T16:05:24Z")

</div>

That’s perfect !!! Thanks a lot !

I put some die(“HEY”) and die(var\_dump($var)) EVERYWHERE without thinking for a second to use error\_reporting !! 😭 😭 😭 😭

Also I didn’t notice that events have their own parameters… my bad !

Thanks a LOT for your help \<3 Now I just have to adjust my pre-update Task hook 🙂
