How to display catalog item variable input in email notification

Bijender
Tera Guru

Hi All,

 

We have a catalog item and need to create a email notification such that notification show the input present in variable field .

 

Like : email notification show "my_name" & "reportee" in email notification

 

Bijender_0-1667833396210.png

 

Kindly advise.

 

Regards,
B

4 REPLIES 4

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Bijender 

 

Please refer below link for your solution:

 

https://www.servicenow.com/community/it-service-management-forum/add-service-catalog-variable-to-ema....

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Create a notification script and include it in your email, here is a notification script i created  a while back to include all non empty variables form a ritm in an email

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

    template.print('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 (value != '') {
            template.space(4);
            template.print('  ' + label + " = " + value + "<br/>");
        }
    }

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

 

-Anurag

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Bijender 

 

You can create a mail script by navigating to System Notification->Email->Notification Email Scripts. You have to call that from your email notification using "${mail_script:<email_script_name>}

 

To display particular Variables, you can use below code in email Notification:

 

template.print('My variable name is '+current.variables.<variable_name>). // Replace <variable_name> with your variable name

 

To display all variables of that Catalog Item, can use below script:

 

for (var key in current.variables) {        
         var v = current.variables[key];        
         template.print('\n' + v.getGlideObject().getQuestion().getLabel() + ": " + v.getDisplayValue() + " <br />");  
} 

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Bijender ,

You can mentioned your variables in HTML notification as below :-

Screenshot 2022-11-07 at 8.42.26 PM.png

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy