How to collect event param in notification mail script

wakespirit
Kilo Guru

Dear all,

I have an email notification with I have defined as below and trigged based on a defined event in registry

see picture

As you can see from the picture the body of the email is fecth using a mail script defined as below

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

	var asset=event.parm1;
	gs.log("CAL : get event " + asset.string());
	
	template.print("<h2>List of records retire or having Cost center changed</h2>. \n\n");
	template.print("<table border=1 bordercolor=black style='width:100%'>");
	template.print("<tr><th align='left'>Asset Tag</th><th align='left'>Model</th><th align='left'>Status</th><th align='left'>SubStatus</th><th align='left'>Cost Center</th></tr>");

//dummy string for test
	template.print('<tr><td>Tag1</td><td>Name1</td><td>Model1</td><td>Status1</td><td>SubStatus1</td>Cost Center 1</tr>');
	
// 	var gr = new GlideRecord ("alm_asset");
// 	gr.addQuery('u_send_record_to_mail', true);
// 	gr.query();
// 	while (gr.next()){
// 		template.print('<tr><td>'+gr.name+'</td><td>'+gr.state+'</td><td>'+gr.cost_centre+'</td></tr>');
// 	}
	
	template.print("</table>");
	
	
})(current, template, email, email_action, event);

My event is fired as below

while (gr.next()){
	assets.push(gr.sys_id.toString());
		}
	gs.eventQueue("Asset.retired.ccchange", null, assets, '');

 

 

Q1 : Does the event parameter of mail script can received event parameter in this context ?

Q2 : If yes how to read back the event  parameter 1 ?

I have try using this 2 line below in order to log information but seems event is note define

var asset=event.parm1;
gs.log("CAL : get event " + asset.string());

How to do to stored event param 1 and used in in mail script ?

regards

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

You can send it as event.parm1, which you are doing already. But you need to pass the table object while calling gs.eventQueue.

 

gs.eventQueue("Asset.retired.ccchange",gr, assets, '');


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

3 REPLIES 3

SanjivMeher
Kilo Patron
Kilo Patron

You can send it as event.parm1, which you are doing already. But you need to pass the table object while calling gs.eventQueue.

 

gs.eventQueue("Asset.retired.ccchange",gr, assets, '');


Please mark this response as correct or helpful if it assisted you with your question.

why do I need to pass the gr object ?

From notification email script I am reading my event field as below

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
	
	var assets = event.parm1.toString().split(',');
	
	template.print("<h2>List of records retire or having Cost center changed</h2>. \n\n");
	template.print("<table border=1 bordercolor=black style='width:100%'>");
	template.print("<tr><th align='left'>Asset Tag</th><th align='left'>Model</th><th align='left'>Status</th><th align='left'>SubStatus</th><th align='left'>Cost Center</th></tr>");
	
	var gr = new GlideRecord('alm_asset');
	gs.log("CAL : RECORDS : " + gr.getRowCount());
	
	
	for (i=0; i < assets.length; i++){
		gr.addEncodedQuery("sys_id="+assets[i]);
		gr.query();
		gr.get(assets[i]);
		gs.log("CAL : FILTER RECORD : " + gr.getRowCount());
		
		
 		template.print('<tr><td>'+gr.getValue('asset_tag')+'</td><td>'+gr.getValue('model')+'</td><td>'+gr.getValue('install_status')+'</td><td>'+gr.getValue('substatus')+'</td><td>'+gr.getValue('cost_center')+'</td></tr>');
	}

	
	
	
		
		template.print("</table>");
		
		
	})(current, template, email, email_action, event);

 

If I pass the gr object in event , how can I update my script above to fetch proper records to be display ?

regard

You need to pass an object of the table on which the notification and event is configured. Because it is mandatory. Without that, your event wont work. Even if you don't use it in the mail script, you need to pass it. I dont see any issue with the mail script. You can keep it as it is.


Please mark this response as correct or helpful if it assisted you with your question.