The CreatorCon Call for Content is officially open! Get started here.

How to call an email script in an email template where some of the fields are pulled from a table.

LK11
Mega Expert

I have to set up a group email notification.   I have an email template in which values for some fields are pulled from a table.   I have written an email script to get the value of one particular field.   But i don't know how to call the email script only for that field in the template along with the rest of the values coming from the table.   Any advise would be appreciated.

Thank you

1 ACCEPTED SOLUTION

If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you


View solution in original post

8 REPLIES 8

Is the release date on the record, on a related record? Where is the release date coming from? If I knew, I could help you with the mail script.



The standard way, as noted above, to call an email notification script is ${mail_script:NameOfMailScript}



If the release date is on a parent record, however, you don't need to call a script for that. You can use



Release: ${parent.release_date}



Using the field picker on the right can help if the data is available in a reference field, drill in to it.



Docs: Notifications


Docs: Links to records in email notifications



LK11
Mega Expert

Hi Chuck,


The release date is always 3 days after the 'created_date' which is on the form.



Thanks


Would it make sense to store that release date in a field on the form? That would make the email easier. You could set it with a business rule. The core script is going to be about the same, but it only needs calculating once, is visible on reports, and easier to retrieve in the email if you've got it on a field on the record.



Just my architectural thoughts.



The business rule would be something like this: (Note this is untested)



Name: Set release date


Table: (your table name)


When: before


Insert: true


Update: false


Advanced: true


Condition: (empty)


Script:



(function executeRule(current, previous /*null when async*/) {


      var release = new GlideDateTime(current.sys_created_on);


        release.addDaysLocalTime(3);


        current.u_release_date = release;


       


})(current, previous);



The mail script method would be similar:



      var release = new GlideDateTime(current.sys_created_on);


        release.addDaysLocalTime(3);


        template.print(release.getDisplayValue());


If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you