How to write the email script

PRAGHATIESH S
Tera Expert

Hi team,

 

In the notification instead of using ${url_ref}, we need to write the email script to link. 

Can someone help here.

1 ACCEPTED SOLUTION

Hi @Mitesh L Pitrod 

Thanks for the response. Actually it's working when I given dev instance. But I will move to next environment right, that time how will instance name changes? Can you pls help me here

View solution in original post

6 REPLIES 6

Deepak Shaerma
Kilo Sage

Hi @PRAGHATIESH S 
Add a Mail Script:
- In the content of the notification (either in the “Message HTML” or “Message Text” field), you can use a mail script to generate your custom URL.
- You will use ${mail_script:script_name} placeholder to call your custom mail script.

Create the Mail Script:
- Navigate to System Notification -> Email Scripts.
- Click on the “New” button to create a new email script.
- Provide a name for your script, such as “Custom URL Script”.
- Set “Applies to” to All.
- In the “Script” field, write your script to generate the URL. Below is an example of a script that generates a URL for an incident:


// Example email script: Custom URL Script
var gr = current;
var url = gs.getProperty(‘glide.servlet.uri’);
url += ‘nav_to.do?uri=incident.do?sys_id=’ + gr.sys_id;
template.print(‘<a href="’ + url + ‘">View Incident</a>’);


Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards
Deepak Sharma

Mitesh L Pitrod
Tera Contributor

Hello,

You can use the below code to add a hyperlink to the email body.

 

 

Replace the number field and table_name according to your need. 

 

 

function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

// Add your code here
template.print('<a href="https://' + gs.getProperty('instance_name')+ '.service-now.com/<table_name>.do?sys_id=' + current.sys_id+'">' + current.number + '</a>' );
})(current, template, email, email_action, event);

 

 Thanks,

MItesh

Hi @Mitesh L Pitrod 

Thanks for the response. Actually it's working when I given dev instance. But I will move to next environment right, that time how will instance name changes? Can you pls help me here

Sorry, working fine.

 

Thanks for the solution.