How to put dynamic URL with dynamic text in a notification

Manaswi1
Kilo Contributor

Hello Folks,

I want to put a dynamic hyperlink with the dynamic text in notification. Below is an example:

Table: announcement

fields: details_url, details_link_text (URL given in the field)

var URL = current.details_url; (normal text)
var link = current.details_link_text;

I want to print the "current.details_link_text" in email script, When we click on the "current.details_link_text" It should take me to the URL i.e  current.details_url.

Can anybody help me out here ?

1 ACCEPTED SOLUTION

Martin Ivanov
Giga Sage
Giga Sage

Hi. Below is the script you need.

It's a bit confusing to name the link URL and the text - link, but it's okay if you understand it like this.

Name your emal script script for example 'getDinamicUrl', then in the notification call ${mail_script:getDinamicUrl}

Please mark Correct and Helpful. Thanks!

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
		
	var URL = current.details_url;
	var link = current.details_link_text;
          // Add your code here
		
	template.print('<a href="'+URL+'" style="font-family: verdana, geneva; font-size: 12pt;">'+link+'</a>');
	
	

})(current, template, email, email_action, event);


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

View solution in original post

3 REPLIES 3

Martin Ivanov
Giga Sage
Giga Sage

Hi. Below is the script you need.

It's a bit confusing to name the link URL and the text - link, but it's okay if you understand it like this.

Name your emal script script for example 'getDinamicUrl', then in the notification call ${mail_script:getDinamicUrl}

Please mark Correct and Helpful. Thanks!

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
		
	var URL = current.details_url;
	var link = current.details_link_text;
          // Add your code here
		
	template.print('<a href="'+URL+'" style="font-family: verdana, geneva; font-size: 12pt;">'+link+'</a>');
	
	

})(current, template, email, email_action, event);


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Ankur Bawiskar
Tera Patron
Tera Patron

@Manaswi 

Please follow the steps shared by Martin and they should help you

Regards
Ankur

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

1__vipind
Tera Contributor

Hi Marin,

If I wish to separate text and URL, then how can I achieve this, for example I have a field string type (u_work_notes) and another URL field type (u_url) and value entered u_work_notes is "try this link" and in URL field mentioned - "www.xyz.com" then i want output - try this link www.xyz.com(this being hyperlink).

Can you please let me know the possible way to achieve the same