Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Issue with Mail Script - Unable to hide text

Angela22
Tera Contributor

I am writing an email notification that advises users when a CI assigned to them has not been logged into for a number of days.   One of the requirements is to check the short_description field of CI and display text in the email if there's an entry in that field.

 

The below script works fine and will print the contents of the Short Description.  

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
       var ciDescript = current.short_description;
    if (ciDescript != null) {
        template.print(ciDescript);
    }
})(current, template, email, email_action, event);

 

However the below script doesn't work and displays the text regardless

 

 
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
    var ciShortDes = current.short_description;
    if (ciShortDes != null) {
        template.print("or the description is incorrect,");
    }
})(current, template, email, email_action, event);
 
I've tried using single and double quotes, declaring the message as a variable etc etc but no luck.
 
    if (ciShortDes != null) {
        var descMess = "or the description is incorrect,";
        template.print(descMess);
 
Any help as to what I'm doing wrong would be greatly appreciated. 
 
 
1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @Angela22 

 

Can we try with it.Just changed in validation logic.

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var ciShortDes = current.getValue('short_description') ;
if (ciShortDes.trim() !== '') {
template.print("or the description is incorrect,");
}

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

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

4 REPLIES 4

Ehab Pilloor
Mega Sage

Hi @Angela22,

 

Hi, I dont think there is an issue with both scripts. Maybe you can try using current.getValue('short_description') instead.

 

Test positive and negative scenarios as well for each script.

 

Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.

 

Kind Regards,

Ehab Pilloor

 

 

Tanushree Maiti
Tera Patron

Hi @Angela22 

 

Can we try with it.Just changed in validation logic.

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var ciShortDes = current.getValue('short_description') ;
if (ciShortDes.trim() !== '') {
template.print("or the description is incorrect,");
}

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

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

That worked.  Thank you so much. 

Ankur Bawiskar
Tera Patron

@Angela22 

try to use toString() and then check in comparison

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader