How to Include a Custom URL with Record sys_id in Email Notification?

Tyler33
Tera Contributor

I'm working on a requirement where, whenever a case is created in ServiceNow, an email notification should be triggered. The email body needs to include a direct URL link to the same case record, but on a different/external platform.

The URL format is standard and looks like this, where the sys_id should dynamically pull from the current case record in ServiceNow:

https://TEST.DEMO.com/tickets/lib/{sys_id}/edit

 

For example, if the sys_id of the case is 7d1f540997e96290be01bb1ad053af06, the final link would be:

https://TEST.DEMO.com/tickets/lib/7d1f540997e96290be01bb1ad053af06/edit

 

My questions:

  • What’s the best way to include this dynamic link in the email body?

  • Should I use an Email Script, or is there another recommended approach?

I’ve tried both approaches but have run into issues where the sys_id does not render as expected in the final email.

 

Example Notification Template (HTML):

<a href="https://TEST.DEMO.com/tickets/lib/${sys_id}/edit">
https://TEST.DEMO.com/tickets/lib/${sys_id}/edit
</a>

 

Sample mail script:

(function runMailScript(current, template, email, email_action, event) {
var link = "https://TEST.DEMO.com/tickets/lib/" + current.sys_id + "/edit";
template.print('<a href="' + link + '">' + link + '</a>');
})();

 

Would appreciate any advice or examples from those who’ve successfully done this.

 



 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Tyler33 

you can include link like this

AnkurBawiskar_0-1748439705962.png

 

AnkurBawiskar_1-1748439719931.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

James Chun
Kilo Patron

Hi @Tyler33,

 

You should be able to use the ${sys_id} within the email notification without writing a mail script.

If you are triggering the email notification from a specific table, you can fetch the ${sys_id}, i.e.

JamesChun_0-1748382544919.png

 

What do you mean by sys_id does not render as expected? Are you saying there is no value in the parameter or something else?

 

Cheers

Thanks James, 

I've tried both a mail script and embedding it directly in the template. I've also confirmed that if I just use ${sys_id} by itself (not inside the URL), it does populate correctly in the notification.

 

What I meant by “sys_id does not render as expected” is that in the email that gets sent, the placeholder ${sys_id} just shows up as-is in the final output — literally ${sys_id} — instead of being replaced with the actual sys_id value from the record.

So rather than a full URL like:
https://TEST.DEMO.com/tickets/lib/7d1f540997e96290be01bb1ad053af06/edit

I'm getting this in the email:
https://TEST.DEMO.com/tickets/lib/${sys_id}/edit

This happens even though the notification is tied to the case table and triggered when a new case is inserted.

 

Screenshot 2025-05-28 at 8.35.26 AM.png

Screenshot 2025-05-27 at 12.44.53 PM.png

The sys  ID that I am attempting to add to the URL does not show up as-is in the final output — it just says  ${sys_id} in the notification. 

On the bottom of the template where I have Sys ID: ${sys_id} - this appends the correct sys_id as expected. 

Ankur Bawiskar
Tera Patron
Tera Patron

@Tyler33 

you can include link like this

AnkurBawiskar_0-1748439705962.png

 

AnkurBawiskar_1-1748439719931.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader