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.

Email template message not applying

coreyo
Giga Contributor

I've updated an email template, however just not showing the links/message.   Not sure what I am missing here.   The notification fires when a comment is made on the request table and is sent to the 'request for'.   I have a mail script to identify is the request for is an internal user or not and handle accordingly.

Short description: ${short_description}

Item: ${cat_item}

</br>

<mail_script>

var internal = current.Request.Requested for.u_internal_user;

function(){

if (internal != 'No') {

return 'To view Request: ${URI_REF}';

}

else if (internal == 'No') {

return 'To view Request: <a href="' + gs.getProperty('glide.servlet.uri') + 'msp/' + '">Click Here</a>';

}

}

template.print();

</mail_script>

1 ACCEPTED SOLUTION

Great! Yeah so variables in email scripts are scoped to the individual script. You don't have a 'internal' variable defined in the second email script block, and it looks like there is an extra unmatched }, and some mismatched quotations so it fails.



You can also use a try catch block to display the error like this.



<mail_script>


try{


if (internal != 'No') {


template.print('To view Request (this is SSO): ${URI_REF}');


} else if (internal == 'No') {


template.print('To view Request (this is MSP): <a href="PORTAL URL HERE">Click Here</a>');


}else template.print('To view Request (this is else SSO): ${URI_REF}');


} catch(err){


  template.print('An error occurred - '+err.message);


}


</mail_script>


View solution in original post

5 REPLIES 5

Great! Yeah so variables in email scripts are scoped to the individual script. You don't have a 'internal' variable defined in the second email script block, and it looks like there is an extra unmatched }, and some mismatched quotations so it fails.



You can also use a try catch block to display the error like this.



<mail_script>


try{


if (internal != 'No') {


template.print('To view Request (this is SSO): ${URI_REF}');


} else if (internal == 'No') {


template.print('To view Request (this is MSP): <a href="PORTAL URL HERE">Click Here</a>');


}else template.print('To view Request (this is else SSO): ${URI_REF}');


} catch(err){


  template.print('An error occurred - '+err.message);


}


</mail_script>