How to call functions defined in email notification scripts

dp11
Tera Guru

Hi,

In the OOB email notification script   "attach_links",   a function attachLinks() is defined. I have the following questions:

1. What is the syntax to call this function in an email notification or email template?

                      I tried ${mail_script:attach-links.attachLinks()} but it did not work

2. Can it be called in another email notification script?

Thanks,

Debashree

1 ACCEPTED SOLUTION

edwin_munoz
Mega Guru

Hello Pati,



1. You just need to include the email script:



${mail_script:attach_links}




If you go to the attach link script you will see that the attachLinks function is already called in the code:



Think of mail scripts as containers of code, once you add them to your email the script is going to be injected into your notification.



2. Technically you could do it, but I think you will have to do it inside your notification. Like this:



${mail_script:attach_links}




<mail_script>


        attachLinks();


</mail_script>






If you want to call a function in a script that is defined on another email script just call it like you would do it normally, just make sure that you add the email script that defined the function before calling it.


View solution in original post

11 REPLIES 11

Right now I don't have any specific code but would like to have an email notification script with several functions defined within it and then


call these functions in several other scripts, notifications, templates as needed, for modularity. So basically, I am planning my implementation


out at this phase.


Thanks,


Debashree


Harish Murikina
Tera Guru

Hi Debashree,



                  Its simple



you can call directly



<mail_script>


attachLinks();




function attachLinks()


{


//Do what ever you want inside function


}




</mail_script>


Thanks for your reply, Harish. But we are now in Eureka where the tags are not preferred but rather you use email notification script


instead. So suppose you have an email notification script called attach_links, the document says that you can include it in your notification using the syntax:


$. However, if there are functions defined in the script, I am not able to find out how you can call a specific function.


Debashree


Lets suppose that attachLinks wasn't called in the attach links notification script. You could create a new notification script called otherScript and inside that script you could call attachLinks normally. attachLinks();



On your email notification you will need to add both scripts, adding first the one that defined the function.



${mail_script:attach_links}




${mail_script:otherScript}




And that's it, but in the particular case of attach_links script, the function is called inside the script already so no need to call it again (Although technically you could do it)


Thanks, Edwin. This is one of the things I was looking for. I will give it a try. -Debashree