Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Catalog item link using Email script in Notification

Rutuja K
Giga Guru

Hi All,

 

I have created email script which should return link to all catalog items one particular service owner owns. Below is email script I created. In this case, there are 3 catalog item Test user owns, I checked logs and url is returning 3 different links BUT in notification only first one is coming correctly and for other 2, sys_id is blank.


 
 

and Catalog item is are not coming in line even after using "\n"

RutujaK_5-1707947941851.png

 

 

RutujaK_3-1707947873170.png

 

 

Please can someone help me understand what I am missing please

Thank you!

 

1 ACCEPTED SOLUTION

Rutuja K
Giga Guru

Below is Email Script: 


// Add your code here
var cNames = event. parm2. tostring();

var cat item link = ''
var cat_item = new GLideRecord ("sc_cat_item") ;
cat_item. addEncodedQuery ('sys_idIN'+ cNames) ;
cat_item. query ();
while(cat_item.next()){
template print ("<a href='https://"+gs.getProperty ('instance_name')+". service-now.com/portal?id=sc_cat_iten&sys_id= "+cat_item.sys_id.toString()+" ' target='_blank' > " + cat_item.name.toString() + " </a><br>");
}) (current, template,
email, email action, event);

View solution in original post

7 REPLIES 7

Thanks @Rutuja K,

 

FYI, use "<br>" instead of "\n" for new line.

 

Can you try printing out the array[i] in your log?

Also, try creating a single variable that concatenates the link and take out the template.print outside of the loop.

e.g.

	var catalogLinks = "";
	for (var i = 0; i < array.length; i++) {
		var link = "&sys_id=" + array[i];
		var url = "<a target='_blank' href = " + link + ">Catalog Item </a><br>";
		catalogLinks += url;
	}
	template.print(catalogLinks);

 

Thanks

Tony Chatfield1
Kilo Patron

Hi, if you are querying for multiple sys_id's, try sys_idIN' + array[i];

Rutuja K
Giga Guru

Below is Email Script: 


// Add your code here
var cNames = event. parm2. tostring();

var cat item link = ''
var cat_item = new GLideRecord ("sc_cat_item") ;
cat_item. addEncodedQuery ('sys_idIN'+ cNames) ;
cat_item. query ();
while(cat_item.next()){
template print ("<a href='https://"+gs.getProperty ('instance_name')+". service-now.com/portal?id=sc_cat_iten&sys_id= "+cat_item.sys_id.toString()+" ' target='_blank' > " + cat_item.name.toString() + " </a><br>");
}) (current, template,
email, email action, event);