Automatic Lead Assignment Workflow Stuck - Assistance Needed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CamiReyes
    Junior Member
    • Apr 2025
    • 4

    #1

    Automatic Lead Assignment Workflow Stuck - Assistance Needed

    My automatic lead assignment workflows are stuck. I'm encountering a "Could not parse" formula error in the logs (example: [2025-05-15 08:54:08] ERROR: (500) Process 6825abb0511d76d15 formula error: Could not parse.).

    Qualified Leads: The workflow gets stuck at a Gateway after attempting external user assignment. The diagram is attached.

    Unqualified Leads: This workflow assigns to the "teams" (Many-to-Many relationship) field but doesn't reach the End Event.

    I'm using PHP Script Tasks for assignment logic. Any ideas on what could be causing this persistent formula parsing error, especially in the context of Gateways or when working with Many-to-Many relationships?

    Thanks for any help!
    Attached Files
    Last edited by CamiReyes; Today, 09:00 AM.
  • lazovic
    Super Moderator
    • Jan 2022
    • 1004

    #2
    Hi CamiReyes,

    Please copy the code of all formula scripts in your flowchart and paste it into the post. This way we can figure out the problem.

    Comment

    • CamiReyes
      Junior Member
      • Apr 2025
      • 4

      #3
      Thanks for your reply!!! lazovic

      First flowchart

      Conditional start event:

      cCRenta != "Menos de $800.000" &&
      cCRenta != "$800.000 a $1.000.000" &&
      cCEdad >= 20 &&
      cCEdad <= 50

      1st Script task:
      // Obtener el lead actual
      $lead = $process->get('targetRecord');

      // Buscar usuarios Externos activos que cumplan las condiciones
      $externos = $this->getEntityManager()
      ->getRepository('User')
      ->where([
      'teamId' => '682427b3d25d84242', // Reemplaza con el ID real
      'isActive' => true,
      'title!=' => $lead->get('cCSistemaDeSalud'),
      'cDailyLeadsAssigned<' => 2
      ])
      ->find();

      // Si hay usuarios disponibles, asignar el lead al primero
      if (!empty($externos)) {
      $user = $externos[0];
      $lead->set('assignedUserId', $user->getId());
      $this->getEntityManager()->saveEntity($lead);
      $process->set('assignedUser', $user); // Guardar el usuario para usarlo luego
      }

      2nd Script task:
      $user = $process->get('assignedUser');
      $currentCount = $user->get('cDailyLeadsAssigned') ?? 0;
      $user->set('cDailyLeadsAssigned', $currentCount + 1);
      $this->getEntityManager()->saveEntity($user);​

      [2025-05-15 09:12:30] ERROR: (500) Process 6825affeef258909c formula error: Could not parse.

      Second flowchart

      Conditional start event:

      ​cCRenta == "Menos de $800.000" ||
      cCRenta == "$800.000 a $1.000.000" ||
      cCEdad < 20 ||
      cCEdad > 50​

      Script task:
      ​$lead = $process->get('targetRecord');
      $teamEjecutivoId = "682427bd62784e807"; // Reemplaza con el ID real
      $lead->set('teamsIds', [$teamEjecutivoId]);
      $this->getEntityManager()->saveEntity($lead);​

      ERROR: (500) Process ... formula error: Attribute name [$teamEjecutivoId] contains not allowed characters.

      Comment

      • lazovic
        Super Moderator
        • Jan 2022
        • 1004

        #4
        CamiReyes,

        Please note that in the Execute Formula Script action or in the Script Task element you need to enter the EspoCRM formula script, not the PHP code. More about the formula script you can find here: https://docs.espocrm.com/administration/formula.

        Comment

        • CamiReyes
          Junior Member
          • Apr 2025
          • 4

          #5
          thanks again lazovic

          Made changes and I keep getting this error:

          Unknown function: empty

          even though I’ve removed every call to empty() from my scripts. I’ve also cleared the cache and restarted the workflows, but the error still appears on every new lead.

          Here are my current configurations:

          First flowchart – Conditional start event expression

          Code:
          cCRenta != "Menos de $800.000" &&
          cCRenta != "$800.000 a $1.000.000" &&
          cCEdad >= 20 &&
          cCEdad <= 50
          Script Task #1 (Execute Formula Script):

          Code:
          $healthSystem = workflow\targetEntity\attribute('cCSistemaDeSalud' );
          $externos = record\findMany(
          'User', 1,
          'cDailyLeadsAssigned', 'asc',
          'teamId=', '682427b3d25d84242',
          'isActive=', true,
          'title!=', $healthSystem,
          'cDailyLeadsAssigned<', 2
          );
          if (array\length($externos) > 0) {
          $userId = array\first($externos);
          record\update(
          'Lead',
          workflow\targetEntity\attribute('id'),
          'assignedUserId',
          $userId
          );
          $$assignedUserId = $userId;
          }

          Script Task #2 (Execute Formula Script):​

          Code:
          $userId = $$assignedUserId;
          $currentCount = record\attribute('User', $userId, 'cDailyLeadsAssigned') ?? 0;
          record\update(
          'User',
          $userId,
          'cDailyLeadsAssigned',
          $currentCount + 1
          );

          Second flowchart – Conditional start event expression

          Code:
          cCRenta == "Menos de $800.000" ||
          cCRenta == "$800.000 a $1.000.000" ||
          cCEdad < 20 ||
          cCEdad > 50

          Script Task (Execute Formula Script) for special leads:​

          Code:
          $teamEjecutivoId = "682427bd62784e807";
          entity\addLinkMultipleId('teams', $teamEjecutivoId);
          ​
          Everything else is pure Formula Script—no PHP, no empty(). Yet the log still shows:​

          Code:
          ERROR: Workflow <ID>: Action failed, startBpmnProcess 0, Unknown function: empty.
          Could there be a hidden call to empty(), or am I missing something in the syntax? Thanks in advance for any pointers!​

          How could I configure all this to correctly assign leads under these conditions? I'm very lost

          ​​
          Last edited by CamiReyes; Today, 07:58 PM.

          Comment

          Working...