Announcement

Collapse
No announcement yet.

Task reminders with formula

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Task reminders with formula

    I am trying to create a task, with reminder 'on time' with entity formula.

    I have :
    PHP Code:
    $TaskName string\concatenate(name' - 'client.name);
    $TaskDueDate string\concatenate(nextRenewal' 11:30:00');
    record\create('Task',
    'name'$TaskName,
    'dateEnd'$TaskDueDate,
    'assignedUserId'assignedUserId
        
    )​ 
    But I have no way to set a 'on time' reminder.

    any ideas?

    *no advanced pack
    Last edited by Emmker; 03-24-2024, 10:50 PM.

  • #2
    In order to understand how to form certain entities in the system, take a look at the Chrome inspector. I think the above screenshot will help. A positive value means time "before" the event
    Attached Files

    Comment


    • Emmker
      Emmker commented
      Editing a comment
      I did just that, but I cannot find a way to translate it in formula script.

  • #3
    Hi Emmker,

    Try to use the following formula script:
    Code:
    $taskName = string\concatenate(name, ' - ', client.name);
    $taskDueDate = string\concatenate(nextRenewal, ' 11:30:00');
    
    $taskId = record\create(
      'Task',
      'name', $taskName,
      'dateEnd', $taskDueDate,
      'assignedUserId', assignedUserId
    )​;
    
    $reminderId = record\create(
        'Reminder',
        'entityId', $taskId,
        'entityType', 'Task',
        'type', 'Popup',
        'userId', assignedUserId,
        'seconds', 0
    );​
    ​​

    Comment


    • #4
      Originally posted by lazovic View Post
      Hi Emmker,

      Try to use the following formula script:
      Code:
      $taskName = string\concatenate(name, ' - ', client.name);
      $taskDueDate = string\concatenate(nextRenewal, ' 11:30:00');
      
      $taskId = record\create(
      'Task',
      'name', $taskName,
      'dateEnd', $taskDueDate,
      'assignedUserId', assignedUserId
      )​;
      
      $reminderId = record\create(
      'Reminder',
      'entityId', $taskId,
      'entityType', 'Task',
      'type', 'Popup',
      'userId', assignedUserId,
      'seconds', 0
      );​
      ​​
      That worked like a charm.

      I just realised that reminder is its own entity.

      Thank you very much

      Comment


      • sleith
        sleith commented
        Editing a comment
        I am having a similar issue and I tried using this example and am not getting the results I am looking for. Would you be able to advise?

    • #5
      I have a similar issue and cannot get this code to add the reminder when the follow up task is created based on selecting a contact date.

      // Set cNextContact to 90 days after cContacted if cContacted is filled
      ifThen(
      cContacted != NULL,
      cNextContact = datetime\addDays(cContacted, 90)
      );

      // Step 1: Create the Task and save its ID in the entity
      ifThen(
      cNextContact != NULL,
      $taskId = record\create(
      'Task',
      'name', '90-Day Follow-up Task',
      'description', 'This customer has not been contacted in 90 days.',
      'dateEnd', cNextContact, // Set due date to cNextContact
      'status', 'Not Started',
      'assignedUserId', 'scottieleith', // Assign to the specific user
      'parentId', id, // Links to the current Account
      'parentType', 'Account' // Specifies that the parent is an Account
      )
      );

      ifThen(
      $taskId != Null,
      $reminderId = record\create(
      'Reminder',
      'type', 'Popup', // Type of reminder (Popup or Email)
      'seconds', 0, // 0 seconds for "on time" reminder
      'userId', 'scottieleith', // Notify the assigned user
      'entityId', $taskId, // Link reminder to the task created above
      'entityType', 'Task', // Set parent entity type as Task
      )
      );​

      Comment


      • #6
        Hi sleith,

        First, be sure to replace username scottieleith with the user ID. You can find it in the address bar when you open the user's Detail View, e.g., in this address: http://test.espo/#User/view/61e67e33b6c91cda4, user ID will be 61e67e33b6c91cda4.

        Next, try this version of the formula script:

        Code:
        // Set cNextContact to 90 days after cContacted if cContacted is filled
        ifThen(
            !cContacted,
            cNextContact = datetime\addDays(cContacted, 90)
            );
        
        // Step 1: Create the Task and save its ID in the entity
        ifThen(
            !cNextContact,
            $taskId = record\create(
                'Task',
                'name', '90-Day Follow-up Task',
                'description', 'This customer has not been contacted in 90 days.',
                'dateEnd', cNextContact, // Set due date to cNextContact
                'status', 'Not Started',
                'assignedUserId', 'USER_ID', // Assign to the specific user
                'parentId', id, // Links to the current Account
                'parentType', 'Account' // Specifies that the parent is an Account
                )
            );
        
        ifThen(
            !$taskId,
            $reminderId = record\create(
                'Reminder',
                'type', 'Popup', // Type of reminder (Popup or Email)
                'seconds', 0, // 0 seconds for "on time" reminder
                'userId', 'USER_ID', // Notify the assigned user
                'entityId', $taskId, // Link reminder to the task created above
                'entityType', 'Task', // Set parent entity type as Task
                )
            );

        Comment


        • sleith
          sleith commented
          Editing a comment
          Hi lazovic,

          Thank you so much for your help, this unfortunately still did not create the reminder with the task when it was created. It didn't work at all with the syntax
          !cContacted
          I had to go back to cContacted != Null
          Here is the last script I had. I appreciate your help but don't waste your time on it, it's not a huge deal but I would like to get it figured out! Thanks again.

          ifThen(
          cContacted != Null,
          cNextContact = datetime\addDays(cContacted, 90)
          );

          // Step 1: Create the Task and save its ID in the entity
          ifThen(
          cNextContact != Null,
          $taskId = record\create(
          'Task',
          'name', '90-Day Follow-up Task',
          'description', 'This customer has not been contacted in 90 days.',
          'dateEnd', cNextContact, // Set due date to cNextContact
          'status', 'Not Started',
          'assignedUserId', '671ae7c3e9bf4fc62', // Assign to the specific user
          'parentId', id, // Links to the current Account
          'parentType', 'Account' // Specifies that the parent is an Account
          )
          );

          ifThen(
          $taskId != Null,
          $reminderId = record\create(
          'Reminder',
          'type', 'Popup', // Type of reminder (Popup or Email)
          'seconds', 0, // 0 seconds for "on time" reminder
          'userId', '671ae7c3e9bf4fc62', // Notify the assigned user
          'entityId', $taskId, // Link reminder to the task created above
          'entityType', 'Task', // Set parent entity type as Task
          )
          );

      • #7
        sleith,

        The field != Null structure is syntactically incorrect. If you want to use the null value (although the structure used in the version I presented is similar), then make sure the value is syntactically correct: https://docs.espocrm.com/administration/formula/#syntax. It should be null, not Null.
        Last edited by lazovic; 10-30-2024, 05:08 PM.

        Comment


        • #8
          sleith,

          Please try using this formula script:
          Code:
          // Set cNextContact to 90 days after cContacted if cContacted is filled
          ifThen(
              cContacted,
              cNextContact = datetime\addDays(cContacted, 90);
              $cNextContact = string\concatenate(cNextContact, ' 10:00:00');
              );
              
          // Step 1: Create the Task and save its ID in the entity
          ifThen(
              cNextContact,
              $taskId = record\create(
                  'Task',
                  'name', '90-Day Follow-up Task',
                  'description', 'This customer has not been contacted in 90 days.',
                  'dateEnd', $cNextContact, // Set due date to cNextContact
                  'status', 'Not Started',
                  'assignedUserId', '65ccae48919863538', // Assign to the specific user
                  'parentId', id, // Links to the current Account
                  'parentType', 'Account' // Specifies that the parent is an Account
                  )
              );
          
          ifThen(
              $taskId,
              $reminderId = record\create(
                  'Reminder',
                  'type', 'Popup', // Type of reminder (Popup or Email)
                  'seconds', 0, // 0 seconds for "on time" reminder
                  'userId', '65ccae48919863538', // Notify the assigned user
                  'entityId', $taskId, // Link reminder to the task created above
                  'entityType', 'Task', // Set parent entity type as Task
                  )
              );

          Comment


          • #9
            That did the trick! Thank you so much for your help

            Comment

            Working...
            X