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

thanks guys!


ur welcome. yes, i did not test the code. i just had written something similar which i remembered could be used here. Glad to hear it worked.


samiul1
Tera Expert

You can use this:


==========================================================


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("<a href='https://" + gs.getProperty('instance_name') + ".service-now.com/sc_req_item.do?sys_id=" + gr.sys_id + "'>"   + gr.number + "</a>:   " + gr.cat_item.getDisplayValue() + "<br />");


}


this one worked perfectly, but thanks Samiul!



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 />");


}


patricklatella
Mega Sage

Hello Ajit,


on a separate topic I started a separate thread regarding automatically clearing the cart when a user opens an order guide...is this something you know about?