FlowCharts Send Http Request (beforeValue) part 2

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

    FlowCharts Send Http Request (beforeValue) part 2

    If a name of an organisation changes, I send it to another system through a webhook like described https://forum.espocrm.com/forum/exte...t-beforevalue

    How do I use the assigned {$$old} and {$$new} vars in an email template in order to send an email in the workflow?




    Last edited by rinorway; 07-28-2021, 09:48 AM. Reason: url broken
  • Maximus
    Senior Member
    • Nov 2018
    • 2731

    #2
    Hello,
    I do not specialize in it, but what response you receive from the target site?
    Are you sure that you need this part in URL: ?oldname={$$old}&newname={$$new}

    Tip:
    Opena target site -> open 'F12' panel -> do update manually -> investigate of how this POST request performs in the 'Network' tab.

    Comment

    • rinorway
      Senior Member
      • Feb 2016
      • 179

      #3
      Originally posted by Maximus
      Hello,
      I do not specialize in it, but what response you receive from the target site?
      Are you sure that you need this part in URL: ?oldname={$$old}&newname={$$new}

      Tip:
      Opena target site -> open 'F12' panel -> do update manually -> investigate of how this POST request performs in the 'Network' tab.
      Maximus, this is only an example and I used ?oldname={$$old}&newname={$$new} only for visual inspection of https://webhook.site , it works fine.

      My question is : How can I use these vars in an Espo EMAIL template, eg :

      Action 1 : execute Espo formula, set $old and $new
      Action 2 : send email, use $old and $new in the email template.

      Is there a way to get these variables in the template?

      Comment

      • Maximus
        Senior Member
        • Nov 2018
        • 2731

        #4
        Missed that part about email. Was confused by the Send HTTP Request action

        If you need to send an email with the variables '$old' and '$new', then you need to try this approach https://docs.espocrm.com/administrat.../#extemailsend. Example:
        Code:
        $old = entity\attributeFetched('name');
        $new = entity\attribute('name');
        $id = record\create(
            'Email',
            'from', 'from-address@test.com',
            'to', 'to-address@test.com',
            'subject', 'Test from formula',
        [COLOR=#27ae60]    'body', 'Hi,\n\nThis is the old name: $old;\nThis is the new name: $new.', [/COLOR]
            'isHtml', false,
            'status', 'Sending'
        );
        ext\email\send($id);
        As you may notice we had to manually create a template within the 'body' attribute. It is not possible to select an Email Template with the ext\email\applyTemplate function and push into it your variables. You can only use one approach of this two.

        Comment

        • rinorway
          Senior Member
          • Feb 2016
          • 179

          #5
          Maximus hmm I tried that, but results in

          This is the old name: $old;
          This is the new name: $new.

          Also variant {$$old} will not render.

          Did you try that?

          Comment

          • Maximus
            Senior Member
            • Nov 2018
            • 2731

            #6
            Ok, I think I know why 'body', 'Hi,\n\nThis is the old name: $old;\nThis is the new name: $new.', doesn't recognize the $new and $old. The logic considers them like a string, not a variable.
            Workaround:
            1. Create a new variable somewhere above called '$body' and use the concatenation function to create the email body you want https://docs.espocrm.com/administrat...ingconcatenate.
            2. Describe the email's 'body' attribute this way
            Code:
            [COLOR=#27ae60]'body', $body, [/COLOR]

            Comment

            • rinorway
              Senior Member
              • Feb 2016
              • 179

              #7
              Of course you are right, a bit cumbersome it is though.

              For doing that a string\sprintf() formula would be handy. Ill try to add that as suggested in https://docs.espocrm.com/development...on-in-formula/

              At the end I think the best solution would be that ext\email\applyTemplate would parse the {$$var} , so that you can apply a template and pass the vars to it, as described
              in https://docs.espocrm.com/administrat...formula-script

              Thank you.

              Comment

              Working...