- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2018 03:06 PM
i am trying to write a business rule suppose if the user becomes inactive reassign all his incidents to his group manager.
After (Update)
Active changes to false :
(function executeRule(current, previous /*null when async*/) {
var inc =new GlideRecord('incident');
var user = current.sys_id;
inc.addQuery('assigned_to',user);
//inc.addQuery('assignment_group',group);
gs.logs('#000');
inc.query();
while(inc.next()){
var aa = new GlideRecord('sys_user_group');
var man = user.sys_user_group.manager;
aa.addQuery('User',user);
gs.logs('#002');
aa.query();
while(aa.next()){
inc.assigned_to = man;
inc.update();
}
}
})(current, previous);
Please help me out. let me know where i am going wrong or if the whole thing is wrong.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2018 11:48 AM
Try this out:
(function executeRule(current, previous /*null when async*/) {
var user = current.getValue("sys_id"); //should usually use a string version of the data
var inc = new GlideRecord("incident");
//added extra filter so closed/cancelled records are not re-assigned
inc.addEncodedQuery("active=true^assigned_to=" + user);
inc.query();
while(inc.next()){
manager = inc.assignment_group.manager.toString();
if (manager){
inc.assigned_to = manager;
} else {
inc.assigned_to = "";
}
inc.update();
}
})(current, previous);
This will set the "Assigned to" field to the current Assignment group's Manager. If there is no Manager, will simply clear the Assigned to field. You would have to deal with that somehow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2018 11:48 AM
Try this out:
(function executeRule(current, previous /*null when async*/) {
var user = current.getValue("sys_id"); //should usually use a string version of the data
var inc = new GlideRecord("incident");
//added extra filter so closed/cancelled records are not re-assigned
inc.addEncodedQuery("active=true^assigned_to=" + user);
inc.query();
while(inc.next()){
manager = inc.assignment_group.manager.toString();
if (manager){
inc.assigned_to = manager;
} else {
inc.assigned_to = "";
}
inc.update();
}
})(current, previous);
This will set the "Assigned to" field to the current Assignment group's Manager. If there is no Manager, will simply clear the Assigned to field. You would have to deal with that somehow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2018 12:26 PM
Hello Jim,
thank you for answering my query. Works like Charm :).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2018 01:15 PM
You are welcome.