Get Variables and it's from Record Producer to email notification script

harishdasari
Tera Guru

Hi,

I have created a email script, which needs to get the variables and it's values from record producer. After record producer is submitted then it will create a record on sn_hr_core_case(HR case) table.

I have created the email script for it, but I am not exactly sure how to get the values.

any can please help how can I accomplish this requirement.

 

Thank you.

 

Here is the below script I have tried, but it is NOT WORKING.

var gift = new GlideRecord('sn_hr_core_case');
	gift.addQuery('sys_id', current.document_id);
	gift.query();
	while(gift.next())
		{
			template.print(item.number + ":   " + item.cat_item.getDisplayValue() + "\n");
           template.print("       Item Options:\n");
           var keys = new Array();
           var set = new GlideappVariablePoolQuestionSet();
           set.setRequestID(gift.sys_id);
           set.load();
           var vs = set.getFlatQuestions();
           for (var i=0; i < vs.size(); i++) {
               if(vs.get(i).getLabel() != '') {
                     template.space(4);
                     template.print('         ' +   vs.get(i).getLabel() + " = <span style='color:red'>" + vs.get(i).getDisplayValue() + "</span>\n");

               }
           }
   }
1 ACCEPTED SOLUTION

vinothkumar
Tera Guru

Harish,

 

You can try something like this and it will work

 

var gift = new GlideRecord('sn_hr_core_case');

gift.addQuery('sys_id', current.sys_id);

gift.query();

if(gift.next()) {

template.print(" Requestor" +  m.variables.variable_name);

}

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Harish,

For me this is working fine. What gets displayed in the email body.

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Shishir Srivast
Mega Sage

I think, var keys = new Array(); can not be used to define an array. Can we replace the var keys = new Array(); with var keys = []; and then try.

var gift = new GlideRecord('sn_hr_core_case');
gift.addQuery('sys_id', current.document_id);
gift.query();
while(gift.next()){
	template.print(item.number + ":   " + item.cat_item.getDisplayValue() + "\n");
	template.print("       Item Options:\n");
	var keys = [];
	var set = new GlideappVariablePoolQuestionSet();
	set.setRequestID(gift.sys_id);
	set.load();
	var vs = set.getFlatQuestions();
	for (var i=0; i < vs.size(); i++) {
		if(vs.get(i).getLabel() != '') {
			template.space(4);
			template.print('         ' +   vs.get(i).getLabel() + " = <span style='color:red'>" + vs.get(i).getDisplayValue() + "</span>\n");
		}
	}
}

harishdasari
Tera Guru

Hi Ankur and Srivastava,

 

Thank you for the response.

 

Not sure what exactly issue is.. it is printing only upto this line below, after that it is not printing.

template.print("       Item Options:\n");

 

here is the complete script below and I made some changes to it, could you please check and let me know what is mistake I am making on the script.

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          // Add your code here
	
	var gift = new GlideRecord('sn_hr_core_case');
	gift.addQuery('sys_id', current.document_id);
	gift.query();
	while(gift.next())
		{
           template.print("       Item Options:\n");
           var keys = [];
	var set = new GlideappVariablePoolQuestionSet();
	set.setRequestID(gift.sys_id);
	set.load();
			
	var vs = set.getFlatQuestions();
	for (var i=0; i < vs.size(); i++) {
		if(vs.get(i).getLabel() != '') {
			template.print('         ' +   vs.get(i).getLabel() + " = <span style='color:red'>" + vs.get(i).getDisplayValue() + "</span>\n");
               }
           }
   }


		

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

Hi Harish,

 

Correct, it won't work in scoped app

following error I got

Evaluator: java.lang.SecurityException: GlideappVariablePoolQuestionSet is not allowed in scoped applications

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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