GlideSubstituteURL().generateURL

shalinichiluka
Kilo Contributor

Hi All,

Can anyone explain me the usage of 'GlideSubstituteURL().generateURL' in the script below or in general.

Script:

template.print("<br />");  

var gr = new GlideRecord("kb_knowledge");

gr.addQuery('source', current.sys_id);

gr.query();

while (gr.next()) {

var link = new GlideSubstituteURL().generateURL(gr, '');

var title = gr.number;

  if (gr.short_description != '') {

  title+= " - " + gr.short_description;

  }

5 REPLIES 5

Justin Abbott
Giga Guru

It appear to be doing anything in the script you pasted. The link variable doesn't appear to be referenced after it's declared.



In general, GlideSubstituteURL().generateURL() will build out a URL for a given GlideRecord.


shalinichiluka
Kilo Contributor

Thank you Justin.



Here is the complete script.



template.print("<br />");  


var gr = new GlideRecord("kb_knowledge");


gr.addQuery('Active', true);


gr.addQuery('valid_to', '<', gs.daysAgo(30));


gr.query();


while (gr.next()) {


  var link = new GlideSubstituteURL().generateURL(gr, '');


  var title = gr.number;


  if (gr.short_description != '') {


  title+= " - " + gr.short_description;


  }



  var anchor = "<a href='" + link +"'>" + title + "</a>";


  template.print(anchor + "<br />");



Does template.print - Prints the output under system log?


Hi Shalini,



No it renders the content in the email body the mail script is called in.



In your case it will generate the link to GlideRecord'ed record with text as short description.



Use gs.log() above/instead of template.print() to display under system log.



Thanks,


Tanaji


shalinichiluka
Kilo Contributor

Thank you Tanaji,



I did not understand what you meant by 'No it renders the content in the email body the mail script is called in'.



Could you explain in detail.



What does template.print in general do?



And what it is doing in this case.


The code here is for Notification Email Scripts.



I know the tag "<br> ..."<br /> is used for line breaking.