I want to display all catalog variables on notification

sunitha _
Tera Contributor

Hi Team,

I want to display the variable in notification which is available on the catalog form, i will create the notification on sc_task table, before that Can anyone suggest the sample email script here. Assume variable name is "requestor".

Thanks in advance      

5 REPLIES 5

Harshad Wagh
Tera Guru

I have this mail script which will help you to display all variables.

var vquest;
	
	var variables = current.variables.getElements();
	for(var key=0;key<variables.length;key++) {
		vquest = variables[key].getQuestion();
			template.print("<p style=\"margin: 0in 2.85pt 0.0001pt 20pt;\"><span style=\"font-family: arial, helvetica, sans-serif; color: #585856;font-size: 11pt;\"><strong><span style=\"color: #00205b;\">" + vquest.getLabel()+ "</span></strong>&nbsp;" + vquest.getDisplayValue() + "<br /></span></p>");
}
		

hi harshad where should I write this script

Hi Sunitha,

You need to write the script provided by Harshad in email notification script

and in the notification body you can call that script like : ${mail_script: name_of_your_script}

 


***Mark Correct or Helpful if it helps.***

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can create email script and then use something like this and include that email script in email body

I assume you know how to create email script and include in email body

Mail script: print_cat_item_request_submitted

Script:

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

    // Add your code here

    template.print('Variable Summary: <br/>');
    
    var ritm = new GlideRecord('sc_req_item');
    ritm.get('sys_id', current.request_item);
    
    var variables = ritm.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/>");
        }
    } 

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

Regards
Ankur

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