script to add hyperlink to results from a GlideRecord

patricklatella
Mega Sage

Hi everyone,

I've got an email script that adds the requested items associated with a parent request to an email as seen below.   What I need is for each of those requested items to appear as a hyperlink to their record in SN.   My email script is below.

find_real_file.png

here's my script...not sure what to add to it to get the hyperlinks going....thanks!

template.print("<p></p><strong>Requested item(s)</strong><br />");

var gr = new GlideRecord("sc_req_item");

gr.addQuery("request", current.sys_id);

gr.query();

while(gr.next()) {

template.print(gr.number + ":   " + gr.cat_item.getDisplayValue() + "<br />");

}

1 ACCEPTED SOLUTION

ajitchandragiri
Giga Expert

here you go..



template.print("<p></p><strong>Requested item(s)</strong><br />");


var baseURL = gs.getProperty('glide.servlet.uri');


var gr = new GlideRecord("sc_req_item");


gr.addQuery("request", current.sys_id);


gr.query();


while(gr.next()) {


template.print(gr.number + ": " + gr.cat_item.getDisplayValue() + "<br />"););


template.print("<a href=" + baseURL + gr.getLink() +">" + gr.number + "</a>");


}


View solution in original post

9 REPLIES 9

ajitchandragiri
Giga Expert

here you go..



template.print("<p></p><strong>Requested item(s)</strong><br />");


var baseURL = gs.getProperty('glide.servlet.uri');


var gr = new GlideRecord("sc_req_item");


gr.addQuery("request", current.sys_id);


gr.query();


while(gr.next()) {


template.print(gr.number + ": " + gr.cat_item.getDisplayValue() + "<br />"););


template.print("<a href=" + baseURL + gr.getLink() +">" + gr.number + "</a>");


}


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Patrick,



Below is the updated code.



template.print("<p></p><strong>Requested item(s)</strong><br />");


var gr = new GlideRecord("sc_req_item");


gr.addQuery("request", current.sys_id);


gr.query();


while(gr.next()) {


var baseURL = gs.getProperty("glide.servlet.uri");


template.print("<a href=" + baseURL +   gr.getLink() +">" + 'inc'+ "</a>" + ":   " + gr.cat_item.getDisplayValue() + "<br />");


}



Note Untested code.


patricklatella
Mega Sage

Hello Ajit,


thanks for the reply.   I'm getting an error with your code on the line below.  



template.print("<p></p><strong>Requested item(s)</strong><br />");


var baseURL = gs.getProperty('glide.servlet.uri');


var gr = new GlideRecord("sc_req_item");


gr.addQuery("request", current.sys_id);


gr.query();


while(gr.next()) {


template.print(gr.number + ": " + gr.cat_item.getDisplayValue() + "<br />");//this line is giving me the red circle alert, so I removed the extra );


template.print("<a href=" + baseURL + gr.getLink() +">" + gr.number + "</a>");


}



I think it's close, here's the result I'm getting...just jumbling the requested item numbers a little.   I only need it to list the number that is the hyperlink, and for that to be the first number.  



find_real_file.png


patricklatella
Mega Sage

actually got it with a little adjustment of your script.  


thanks!



template.print("<p></p><strong>Requested item(s)</strong><br />");


var baseURL = gs.getProperty('glide.servlet.uri');


var gr = new GlideRecord("sc_req_item");


gr.addQuery("request", current.sys_id);


gr.query();


while(gr.next()) {


template.print("<a href=" + baseURL + gr.getLink() +">" + gr.number + "</a>");


template.print(": " + gr.cat_item.getDisplayValue() + "<br />");


}