Workflow: change in billing data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rinorway
    Senior Member
    • Feb 2016
    • 179

    Workflow: change in billing data

    I want to have the old and the new billing postal code sent by email if it changed.

    Condition : Formula : entity\isAttributeChanged('billingAddressPostalCod e')

    Could you give an example on how to get the current and
    previous billing postal code in the email to be sent out?

    Thank you
    Last edited by rinorway; 01-21-2020, 11:16 AM.
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    I recommend using BPM for this.

    You can assign a previous value to a process variable. Then you can use this variable in an email template (since the recent advanced pack version).

    Code:
    $previousCode = entity\attributeFetched('billingAddressPorstalCode');
    $newCode = entity\attribute('billingAddressPorstalCode');
    In the email template:
    Code:
    {$$previousCode}
    
    {$$newCode}
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • rinorway
      Senior Member
      • Feb 2016
      • 179

      #3
      Thank you,

      Where do assign the process variables in workflow?
      I know I can do assignment in "update target record" but not in "send email"
      I know you can do a script task in BPM, it would be nice to have script task as possible action in workflow as well.
      BPM is great for complex workflow, but I want to use these vars in workflow, not BPM


      Comment

      • yuri
        Member
        • Mar 2014
        • 8440

        #4
        It's not possible with workflows.

        You can do a trick by copying a previous value to another field. This will work out in workflow. You need to run sequential workflow. First updates, second sends email. It's almost the same complexity as BPM, but w/o having not needed processes stored in the system.
        Last edited by yuri; 01-21-2020, 10:57 AM.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • yuri
          Member
          • Mar 2014
          • 8440

          #5
          But I'd recommend using BPM with self removal.

          Update Process Record > formula:

          deleted = 1;
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment

          • rinorway
            Senior Member
            • Feb 2016
            • 179

            #6
            Ok tried BPM, but that will result in trigger AFTER the change, yielding both attributes to be the same.

            Click image for larger version

Name:	2020-01-21_11-50-48.png
Views:	239
Size:	8.8 KB
ID:	55074

            Code:
            {
              "list": [
                {
                  "type": "eventStartConditional",
                  "triggerType": "afterRecordSaved",
                  "isInterrupting": false,
                  "id": "alm5zl8r79",
                  "text": "billingAddressPorstalCode  changed",
                  "conditionsFormula": "entity\\isAttributeChanged('billingAddressPostalCode')"
                },
                {
                  "type": "taskScript",
                  "id": "rkq6hz7o7k",
                  "text": "assign $previousCode and $newCode",
                  "formula": "$previousCode = entity\\attributeFetched('billingAddressPostalCode');\n$newCode = entity\\attribute('billingAddressPostalCode');"
                },
                {
                  "type": "taskSendMessage",
                  "from": "system",
                  "to": "specifiedUsers",
                  "messageType": "Email",
                  "text": "Send email with old and new values",
                  "emailTemplateName": "Old new billing postal code"
                }
              ],
              "createdEntitiesData": {}
            Any suggestion what is wrong here ?

            Comment

            • yuri
              Member
              • Mar 2014
              • 8440

              #7
              Really, I forgot the way a process is initiated. I'd add another custom field and set it with a previous value w/ a regular workflow rule.
              If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

              Comment

              • rinorway
                Senior Member
                • Feb 2016
                • 179

                #8
                Ok finally ended up with adding this logic to the entity formula (before save script).
                There is no "Before saving record" trigger, hence you will not be able to do the attributeFetched()

                ifThen(entity\isAttributeChanged('step'),
                pstep=entity\attributeFetched('step');
                $logline=string\concatenate(log,"\n At **",datetime\today(),"** step changed from **",pstep," ** to **",step,"**");
                log=$logline;
                );


                For those wondering : the "before save script" is in the entity manager at the drop down carret.

                Comment

                Working...