Undefined values showing in email notification

othomas1
Kilo Guru

I have an email script and a notification, my notification is showing "undefined" for certain variables i am trying to reference, does anyone know what this could be the cause of this?

Email script:

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

var acl = new GlideRecord('u_cmdb_ci_table_access_parameters');
//var obj = JSON.parse(event.parm2);
acl.addQuery('u_number', current.sys_id);
acl.addQuery('u_class', current.sys_id);
acl.addQuery('u_group_all', current.sys_id);
acl.query();
//acl.getRowCount();
//gs.log('33');

//while(acl.next()){

email.setSubject("CMDB Group ACL Deactivated for " + acl.u_class.getDisplayValue() + " Class ");
template.print('<a href="/u_cmdb_ci_table_access_parameters.do?sys_id=' + acl.sys_id + '">' + acl.u_number + '</a>');
template.print("has been deactivated. The group" + "" + acl.u_group_all.getDisplayValue() + "" + "" + "is no longer active. + '<br/>");
template.print("Please reach out to stakeholders to identify whether a replacement" + "" + acl.u_class.getDisplayValue() + "" + "ACL is needed.<br/>");
gs.log('99');

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

 

 

 

 

find_real_file.png

12 REPLIES 12

Alikutty A
Tera Sage

Hi,

Please try this out and see if it works for you.

var acl = new GlideRecord('u_cmdb_ci_table_access_parameters');
acl.addQuery('u_number', current.sys_id);
acl.addQuery('u_class', current.sys_id);
acl.addQuery('u_group_all', current.sys_id);
acl.query();
acl.next();

email.setSubject("CMDB Group ACL Deactivated for " + acl.u_class.getDisplayValue() + " Class ");
template.print('<a href="/u_cmdb_ci_table_access_parameters.do?sys_id=' + acl.sys_id + '">' + acl.u_number + '</a>');
template.print("has been deactivated. The group" + "" + acl.u_group_all.getDisplayValue() + "" + "" + "is no longer active. + '<br/>");
template.print("Please reach out to stakeholders to identify whether a replacement" + "" + acl.u_class.getDisplayValue() + "" + "ACL is needed.<br/>");
gs.log('99');

Thanks

Hello Alikutty,

I tried those changes but i am still getting the undefined values.

AbhishekGardade
Giga Sage

1. Remove while loop and add if loop.

2. Have you tried something like this -

acl.getDisplayValue('u_class') OR acl.u_class.name

If it works then try for other variables.

Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

dvp
Mega Sage
Mega Sage

to get the values of the queried records you should have .next()

 

Try the below script

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
	
	var acl = new GlideRecord('u_cmdb_ci_table_access_parameters');
	//var obj = JSON.parse(event.parm2);
	acl.addQuery('u_number', current.sys_id);
	acl.addQuery('u_class', current.sys_id);
	acl.addQuery('u_group_all', current.sys_id);
	acl.query();
	//acl.getRowCount();
	//gs.log('33');
	
	if(acl.next()){
		
		email.setSubject("CMDB Group ACL Deactivated for " + acl.u_class.getDisplayValue() + " Class ");
		template.print('<a href="/u_cmdb_ci_table_access_parameters.do?sys_id=' + acl.sys_id + '">' + acl.u_number + '</a>');
		template.print("has been deactivated. The group" + "" + acl.u_group_all.getDisplayValue() + "" + "" + "is no longer active. + '<br/>");
		template.print("Please reach out to stakeholders to identify whether a replacement" + "" + acl.u_class.getDisplayValue() + "" + "ACL is needed.<br/>");
		gs.log('99');
		
	}
	})(current, template, email, email_action, event);

 

Also i think your query might not be correct. You might have to update current.sys_id with the correct ones

acl.addQuery('u_number', current.sys_id);
acl.addQuery('u_class', current.sys_id);
acl.addQuery('u_group_all', current.sys_id);