event.parm1 in mail script retuning event creator sys id

Natalie Scholey
Tera Contributor

Hi guys,

I have an event created by a workflow, and within the event I have got code pulling back a string containing comments into parameter 1.

What I want to do now with this string is pull it into an email notification, however using the below mail script that I have frankensteined from other forum pieces of code I found isn't working (can you tell I'm not a developer!?)

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
	
    var comment = event.parm1;
	template.print('Comments: '+comment+"<br>");
	
})(current, template, email, email_action, event);

What this script is returning is the sys_id of the event creator in the place of 'comment'.

Is there any way I can get the mail script to pull the string from the parm1 field of the event and put it into an email notification?

Please help

4 REPLIES 4

Mehta
Kilo Sage

The above script is correct. It will fetch whatever value you are passing into the parameter 1 ( parm1 ) of the event.  The issue should be when you are using gs.eventQueue(); 

The syntax should be gs.eventQueue("eventname",current, parm1, parm2); . You should sent the comments in parm1. 

Please share the script where you are using gs.eventQueue().

Sankar N
Kilo Guru

It looks like the issue with your script is that you are trying to access the parm1 field directly from the event GlideRecord. Instead, you need to use the getValue() method to retrieve the value of the parm1 parameter. Here is an updated version of your script that should work:

 

(function runMailScript(current, template, email, email_action, event) {
  var comment = event.getValue('parm1');
  template.print('Comments: ' + comment + '<br>');
})(current, template, email, email_action, event);

 

This script should retrieve the value of the parm1 parameter from the event GlideRecord and store it in the comment variable. Then, it will print the comment value in the email notification using the template.print() method.

Make sure that you have configured the email notification correctly, including setting the appropriate recipient, subject, and body. Also, double-check that the event you are using has the parm1 parameter populated with the comment string you want to include in the email.

 

Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Aaron Struphar
Kilo Guru

I am having the same issue. It's pulling the event creator's sys_id (so in my case, it's pulling my user's sys_id) instead of the parm 1.

 

(function runMailScript(current, template, email, email_action, event) {
var days = event.getValue('parm1');
template.print(days+"");

Edxavier Robert
Mega Sage

Hi, 

Just create a mail script like this, where you query to 'sysevent' table to get the param1. Replace 'nameOfEvent' with the name of your event.

 

 

 

var recString = new String();
var gr2 = new GlideRecord("sysevent");
	gr2.addQuery('name', 'nameOftheEvent');
	gr2.addQuery('instance', current.sys_id);
	gr2.orderByDesc('processed');
	gr2.setLimit(1);
	gr2.query();
	while(gr2.next()){
		
		recString = gr2.parm1;		
		template.print(recString);
		email.setSubject("Certificate on server "+current.name+" is about to expire");
	}
})(current, template, email, email_action, event);

 

 

 

Then in the email notification call that mail script using: ${mail_script:NameOfTheMailScript}

Example: 

${mail_script:certificate_expiry}