Notification Email script with parameters

ASA5
Kilo Sage

Hello ,

Can we use parameters when calling email script to do something like this   : ${mail_script:show_informations("first info","second info")} ?

Thank you !

11 REPLIES 11

Chuck Tomasi
Tera Patron

Hi Abdel,



Unfortunately the mail script API does not allow parameters to be passed at this time. It does, however, have access to the event parameters and other objects.



Scripting for Email Notifications - ServiceNow Wiki


Email Notifications - ServiceNow Wiki



You could, potentially pass information via the event parameters if the message was generated from an event.


johnram
ServiceNow Employee
ServiceNow Employee

The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here:


Scripting for Email Notifications
Create an Email Notification




Visit http://docs.servicenow.com for the latest product documentation


SanjivMeher
Kilo Patron
Kilo Patron

Hi Abdel,



Yes. Whatever your write inside mail script access the current record in notification and can access event parm1 and parm2.



Below should be format in the notification. The notification will automatically convert the mailx script part to a notification email script.



<mail_script>


show_informations("first info","second info");



function show_informations(p1,p2)


{


Your Script


}


</mail_script>



Please mark this response as correct or helpful if it assisted you with your question.

ASA5
Kilo Sage

thank you for the answers ,



Actually I have some email templates with a lot of links :



  1. <div>  
  2.   <h2> Links : </h2>  
  3.   <a href="link1">go</a>  
  4.   <a href="link2">go</a>  
  5.   <a href="link3">go</a>  
  6.   <a href="link4">go</a>  
  7.   <a href="link5">go</a>  
  8.   <a href="link6">go</a>  
  9. </div>  


And I need to add query string to each link using email script :



  1. <div>  
  2.   <h2> Links : </h2>  
  3.   <a href="link1?${mail_script:appendParamsLink1}">go</a>  
  4.   <a href="link2?${mail_script:appendParamsLink2}">go</a>  
  5.   <a href="link3?${mail_script:appendParamsLink3}">go</a>  
  6.   .  
  7.   .  
  8.   .  
  9. </div>



  1. //appendParamsLink1 Email script for the first link  
  2. printParams();  
  3.  
  4. function printParams(){  
  5.   template.print("param1=valueLink1&param2=valueLink2..");  
  6. }



The problem is I must have as much email script as links which is not easy to maintain.



That's why if we can call mail script with parameters it would be much easier :



  1. <div>  
  2.   <h2> Links : </h2>  
  3.   <a href="link1?${mail_script:printParams("value1","value2")}">go</a>  
  4.   <a href="link2?${mail_script:printParams("value1","value2")}">go</a>  
  5.   <a href="link3?${mail_script:printParams("value1","value2")}">go</a>  
  6.   .  
  7.   .  
  8.   .  
  9. </div>  



  1. //We can have a generic Email script for all the links  
  2. function printParams(value1,value2){  
  3.   template.print("param1=value1 ¶m2=value2..");  
  4. }  


Maybe there an other way to do it ??


Hi Abdel,



I would suggest building this whole thing using an email script. Dont call indivudual mail script. Starting from '<a href' , Everything should be in the mail script.


  1.   <a href="link1?${mail_script:appendParamsLink1}">go</a>
  2.   <a href="link2?${mail_script:appendParamsLink2}">go</a>
  3.   <a href="link3?${mail_script:appendParamsLink3}">go</a>
  4.   .
  5.   .
  6.   .

Please mark this response as correct or helpful if it assisted you with your question.