How do i get the email template ID in formula

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murugappan
    Active Community Member
    • Aug 2017
    • 467

    How do i get the email template ID in formula

    Hi,

    I am trying to send an email using workflow "ext\email\applyTemplate(EMAIL_ID, EMAIL_TEMPLATE_ID, [PARENT_TYPE, PARENT_ID])​ "as follows:

    HTML Code:
    $emailId = record\create(
    'Email',
    'to', entity\attribute('emailAddress'),
    'parentType', 'Case'
    );
    ext\email\applyTemplate($emailId, 'auto-reply-for-admission');
    ext\email\send($emailId);​
    Its seems to work except that the email contents are empty. I am guessing it is because the email template id is wrong. The name is "Auto Reply for Admission". I tried all tricks but nothing works. How do i get email template id as the formula states? Also the email sent is not registered in Case's History or Stream.
    Last edited by murugappan; 01-22-2024, 06:14 AM.
  • yuri
    Member
    • Mar 2014
    • 8444

    #2
    Hi,

    Obtain a record ID from the address bar.

    Click image for larger version

Name:	image.png
Views:	125
Size:	19.7 KB
ID:	101818
    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

    • murugappan
      Active Community Member
      • Aug 2017
      • 467

      #3
      yuri ,

      Thank you so much the email was sent successfully. But the email is not logged into stream for the case or the history for the case. How can i achieve that?

      Comment

      • lazovic
        Super Moderator
        • Jan 2022
        • 809

        #4
        Hi murugappan,

        You should add parentId attribute (Case ID) to the following part of the formula script:
        Code:
        $emailId = record\create(
          'Email',
          'to', entity\attribute('emailAddress'),
          'parentType', 'Case'
        );​
        As a result, this part will look like this:​
        Code:
        $emailId = record\create(
          'Email',
          'to', entity\attribute('emailAddress'),
          'parentType', 'Case',
          'parentId', 'your-case-id'
        );​

        Thus, an email will be related to the required case.

        Comment


        • murugappan
          murugappan commented
          Editing a comment
          lazovic,

          Thank you for the update. It worked. In fact, i have extended the formula to include the "from" address as well.
      Working...