In notification body need show values as NA

Siva82
Tera Expert

Hi Team,

 

I have created some variables and applied UI policies for them. However, I need the notification body to display "NA" values if the variables are hidden at the form level due to the UI policy. This means that if the variables are not submitted, their values should appear as empty in the notification body.

 

How Can I achive empety variable as "NA" In notification Body,Can you help on that

 

Thank you in adavance

 

Thank you

Sivananda Reddy

1 ACCEPTED SOLUTION

@Siva82 

something like this in email script of RITM notification

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here

    template.print('RITM Variables: <br/>');

    var variables = current.variables.getElements();
    for (var i = 0; i < variables.length; i++) {
        var question = variables[i].getQuestion();
        var label = question.getLabel();
        var value = question.getDisplayValue();
        if (label != '' && value != '') {
            template.space(4);
            template.print('  ' + label + " = " + value + "<br/>");
        } else if (value == '') {
            template.space(4);
            template.print('  ' + label + " = " + 'NA' + "<br/>");
        }
    }

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Siva82 

you can use email script and check if the variable value is empty then print NA

What did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Siva82 

something like this in email script of RITM notification

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here

    template.print('RITM Variables: <br/>');

    var variables = current.variables.getElements();
    for (var i = 0; i < variables.length; i++) {
        var question = variables[i].getQuestion();
        var label = question.getLabel();
        var value = question.getDisplayValue();
        if (label != '' && value != '') {
            template.space(4);
            template.print('  ' + label + " = " + value + "<br/>");
        } else if (value == '') {
            template.space(4);
            template.print('  ' + label + " = " + 'NA' + "<br/>");
        }
    }

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar 

 

It works. Thank you so much

Debasis Pati
Tera Guru

Hello @Siva82 ,

You can call an email script in your notification.
How to call email script from email notification this you can find in the below
https://www.servicenow.com/community/developer-forum/how-to-call-email-script-to-notification/m-p/18...


and then in email script you can directly access variables and check for the variable value something like the below
for example your variable name is x which is hided on the form and you want to print the value as NA for the same then you can write the below in your email script
 var x = current.variables.x;

if(x=='')

{

template.print("X : "NA");

}

the above script will print NA if the value sof x is blank.
Note:Please replace the backend name of your variable "X" where "x" is present.

Please mark it as correct/useful if this helped you.

Regards,
Debasis