# \[SOLVED\] Creating a plugin with decision (addDecision) and execute the event to evaluate

**URL:** <https://forum.mautic.org/t/solved-creating-a-plugin-with-decision-adddecision-and-execute-the-event-to-evaluate/35999>\
**Category:** Development\
**Tags:** community, development, integrations-plugins\
**Created:** [June 28, 2025, 8:49pm UTC](https://forum.mautic.org/t/solved-creating-a-plugin-with-decision-adddecision-and-execute-the-event-to-evaluate/35999 "2025-06-28T20:49:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardopxl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ricardopxl/32/14187_2.png) [@ricardopxl](https://forum.mautic.org/u/ricardopxl)\
**Post date:** [June 28, 2025, 8:49pm UTC](https://forum.mautic.org/t/solved-creating-a-plugin-with-decision-adddecision-and-execute-the-event-to-evaluate/35999/1 "2025-06-28T20:49:06Z")

</div>

### What i’m doing / Plugin to limit daily executions

I’m creating a simple plugin to add a new Decision in the Campaign Builder. The goal is to limit the number of campaign executions per day and I want share a problem and how I fix, if somebody have the same problem.

### Screenshot 1 - Function “onCampaignBuild” it’s working

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/5/5a1b88766c1b0f0644487fdbdc807edf95d7c761.png)

### Screenshot 2 - Campaign

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/1/1c18db1aad55c6fa075b26072af916df8f492590.png)

The subscriber already exists

```auto
"mautic.campaign_limit.daily_limit" event
-----------------------------------------

 ------- ------------------------------------------------------------------------------------------------- ---------- 
  Order Callable Priority  
 ------- ------------------------------------------------------------------------------------------------- ---------- 
  #1 MauticPlugin\MauticCampaignLimitBundle\EventListener\CampaignSubscriber::onDailyLimitEvaluate() 0         
 ------- ------------------------------------------------------------------------------------------------- ---------- 

```

### My current problem

Already read the documentation:

> **[Campaigns — Mautic Developer Documentation 3.0.0 documentation](https://devdocs.mautic.org/en/5.x/components/campaigns.html#registering-a-campaign-decision)**

But when the campaign runs and checks the decision, my custom `eventName` is never triggered.  
As a result, it always returns ` **false** `, and my function `**onDailyLimitEvaluate()**` is never executed.

This is my current file CampaignSubscriber.php

```auto
<?php

namespace MauticPlugin\MauticCampaignLimitBundle\EventListener;

use Doctrine\ORM\EntityManagerInterface;
use Mautic\CampaignBundle\CampaignEvents;
use Mautic\CampaignBundle\Event\CampaignBuilderEvent;
use Mautic\CampaignBundle\Event\CampaignExecutionEvent;
use MauticPlugin\MauticCampaignLimitBundle\Form\Type\DailyLimitType;
use MauticPlugin\MauticCampaignLimitBundle\Service\LimitCheckerService;
use MauticPlugin\MauticCampaignLimitBundle\Event\CampaignLimitEvents;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CampaignSubscriber implements EventSubscriberInterface
{
    private EntityManagerInterface $entityManager;
    private LoggerInterface $logger;
    private LimitCheckerService $limitChecker;

    private const N8N_WEBHOOK_URL = 'https://flow.cloud.digitag.cl/webhook/2a89c8cf-45e6-4dca-84b3-6fc58b11663e';

    public function __construct(EntityManagerInterface $entityManager, LoggerInterface $logger, LimitCheckerService $limitChecker)
    {
        $this->entityManager = $entityManager;
        $this->logger = $logger;
        $this->limitChecker = $limitChecker; // Asignamos el servicio inyectado
    }

    public static function getSubscribedEvents(): array
    {
        return [
            CampaignEvents::CAMPAIGN_ON_BUILD => ['onCampaignBuild', 0],
            CampaignLimitEvents::EVALUATE_CAMPAIGN_DECISION => ['onDailyLimitEvaluate', 0],
        ];
    }

    public function onCampaignBuild(CampaignBuilderEvent $event): void
    {
        $event->addDecision(
            'campaign_limit.daily_limit',
            [
                'label' => 'mautic.campaign_limit.decision.daily_limit',
                'description' => 'mautic.campaign_limit.decision.daily_limit.description',
                'eventName' => CampaignLimitEvents::EVALUATE_CAMPAIGN_DECISION,
                'formType' => DailyLimitType::class,
                'formTypeOptions' => ['label' => false],

                'channel' => 'campaign_limit',
                'channelIdField' => 'limitKey',
            ]
        );

        $this->logger->info('Campaign Limit: Daily Limit decision registered in campaign builder');
    }

    public function onDailyLimitEvaluate(CampaignExecutionEvent $event): void
    {
        
        $event->setResult(true);
            return;
    }

}

```

### Value of my constant

public const EVALUATE\_CAMPAIGN\_DECISION = ‘mautic.campaign\_limit.daily\_limit’;

### Solution

To be sure you will execute the decision in the campaign I did this change:

**Before:**  
CampaignLimitEvents::EVALUATE\_CAMPAIGN\_DECISION =\> [‘onDailyLimitEvaluate’, 0],

**Now:**  
CampaignEvents::ON\_EVENT\_DECISION\_EVALUATION =\> [‘onDailyLimitEvaluate’, 0],

The mautic.campaign\_on\_event\_decision\_evaluation event is dispatched when a campaign decision is to be evaluated.

**My Enviroment**  
My Mautic version is: 5.2  
My PHP version is: PHP 8.3.11
