How to get a URL text from a variable to appear as a link in email notification

ubaid1
Giga Contributor

Hi,

I have a link that is inputted by the HR manager to indicate the URL of a induction handbook. When a new starter process is invoked.

I want this to appear as a link in the email notification along side the blurb if a link has been added on the welcome email.

Following is as far as i got on the email notification script, but my scripting is weak and need a little help here.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,

                  /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,

                  /* Optional GlideRecord */ event)

{

var url = '';

var reqItm = new GlideRecord('sc_req_item');

reqItm.get(event.parm2);

if(reqItm.variables.url != ''){

template.print ("Please follow this link to access your Induction Handbook." );

template.print (reqItm.variables.url);

}

else{

url = '';

 

}

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

This gives me the following:

But I cant get the space between the handbook and https, and also i cant get the https part to appear as a link.

.........

Please follow this link to access your Induction Handbook.https://yyyyyyyy.com/ABC/Support

......

1 ACCEPTED SOLUTION

christopheriron
Tera Expert

Hi ubaid,



I haven't tested but I believe the below should work, you need to process HTML along with the plain text.



(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


                  /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


                  /* Optional GlideRecord */ event)


{


var url = '';


var reqItm = new GlideRecord('sc_req_item');


reqItm.get(event.parm2);


if(reqItm.variables.url != ''){




template.print ("Please follow this link to access your Induction Handbook." );


template.print('<br/>')


template.print ('<a href="' + reqItm.variables.url + '"></href>');



}



else{



url = '';



}


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



Kind regards


View solution in original post

3 REPLIES 3

christopheriron
Tera Expert

Hi ubaid,



I haven't tested but I believe the below should work, you need to process HTML along with the plain text.



(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


                  /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


                  /* Optional GlideRecord */ event)


{


var url = '';


var reqItm = new GlideRecord('sc_req_item');


reqItm.get(event.parm2);


if(reqItm.variables.url != ''){




template.print ("Please follow this link to access your Induction Handbook." );


template.print('<br/>')


template.print ('<a href="' + reqItm.variables.url + '"></href>');



}



else{



url = '';



}


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



Kind regards


Thanks Chris,



That did the trick. Adding a semicolon after <br/> and also adding a link text so it does not make any other text in the notification following the script the link.



Many Thanks.




I did need to modify slight.


(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


                  /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


                  /* Optional GlideRecord */ event)


{


var url = '';


var reqItm = new GlideRecord('sc_req_item');


reqItm.get(event.parm2);


if(reqItm.variables.url != ''){




template.print ("Please follow this link to access your Induction Handbook." );


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


template.print ('<a href="' + reqItm.variables.url + '">Click here to view magazine</href>');



}



else{



url = '';



}


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