Automatic Lead Assignment Workflow Stuck - Assistance Needed

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

    #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
      • 3

      #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

        Working...