- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2019 07:07 AM
i have an email script/business rule working together. When i try to query fields from the table in my script, it removes everything from my notification.
When a user is terminated that is listed in the user field of a u_cmdb_ci_table_access_parameters record, a notification is supposed to go out per CTAP record found. Instead 1 email is going out with all of the user acl records from the u_cmdb_ci_table_access_parameters table.
The notification i am calling is on the u_staffing_events table, why cant i use current to successfully select the appropriate record?
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
//var lob = ["user", "user_name"];
var sysUser = new GlideRecord('u_staffing_events');
sysUser.addActiveQuery();
//sysUser.addQuery('user_name', current.u_employee_id);
sysUser.query();
//JSUtil.logObject(lob);
if(sysUser.next()) {
var usrAcl = new GlideRecord('u_cmdb_ci_table_access_parameters');
usrAcl.addQuery('u_access_entity', '1');
//usrAcl.addQuery('u_user_all', current.sysUser);
usrAcl.addActiveQuery();
usrAcl.query();
while(usrAcl.next()){
{
email.setSubject("CMDB User ACL Deactivated for " + usrAcl.getDisplayValue('u_class') + " Class ");
template.print('<a href="/u_cmdb_ci_table_access_parameters.do?sys_id='+ usrAcl.sys_id +'">'+ usrAcl.u_number +'</a>' + "" + " "+ "has been deactivated.<br/>");
template.print("The user " + usrAcl.u_user_all.getDisplayValue() + " "+ "is no longer active.<br/>");
template.print("Please reach out to stakeholders to identify whether a replacement " + usrAcl.getDisplayValue('u_class') + " ACL is needed.<br/>");
}
}
}
})(current, template, email, email_action, event);
Business rule:
Table: u_staffing_events
(function executeRule(current, previous /*null when async*/) {
var sysUser = new GlideRecord('sys_user');
sysUser.addQuery('user_name', current.u_employee_id);
sysUser.query();
if (sysUser.next()) {
var cmdbCiAcl = new GlideRecord('u_cmdb_ci_table_access_parameters');
cmdbCiAcl.addQuery('u_access_entity', '1');
cmdbCiAcl.addQuery('u_user_all', sysUser.sys_id);
cmdbCiAcl.addQuery('u_active', true);
cmdbCiAcl.setLimit(1);
cmdbCiAcl.query();
while (cmdbCiAcl.next()) {
cmdbCiAcl.u_active = false;
cmdbCiAcl.update();
gs.eventQueueScheduled("user.terminate", current, gs.getUserID(), gs.getUserName(), current.active);
}
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2019 07:21 AM
The current object references the object on which the script is running, in a mail script this is the record the notification is triggered from. Think of current as a glide record but it has queried the table you're in and acquired the record you're on.
In the addQuery line you have highlighted there you seem to be saying current.sysUser. sysUser in this context is a glide record to the u_staffing_events table. If you want to reference the record you have obtained with the glide record you can use sysUser.getUniqueValue()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2019 07:21 AM
The current object references the object on which the script is running, in a mail script this is the record the notification is triggered from. Think of current as a glide record but it has queried the table you're in and acquired the record you're on.
In the addQuery line you have highlighted there you seem to be saying current.sysUser. sysUser in this context is a glide record to the u_staffing_events table. If you want to reference the record you have obtained with the glide record you can use sysUser.getUniqueValue()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2019 07:28 AM