- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 11:52 PM
I need to write a scheduled job to reassign resolved incidents to the assignment group manager whenever the assigned to user becomes inactive in sys_user table.
State should be resolved. I wrote the below query. Doesn't seem to work.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2024 06:47 AM
Hi @sravya vemula ,
You can write a simple schedule job to run daily as shown below,
This checks for all the incident which are closed, resolved or cancelled and Check for assigned to user is active or not.
var gr = new GlideRecord('incident');
gr.addEncodedQuery('stateIN6,7,8');
gr.addQuery('assigned_to.active', false);
gr.query();
while (gr.next()) {
// gs.info('Assignment manager ' + gr.assignment_group.manager + 'Incident ' + gr.number);
gr.assigned_to = gr.assignment_group.manager;
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2024 12:03 AM
Hi,
This requirement seems to be more of a Flow/Business rule kind of thing.
Is the intent really to do it as a scheduled job (i.e. run at specific date/time intervals) ?
Or should it run when an event happens? For example when a user goes inactive.
The thing that does not work here, is the query with the part of ...user.active.changesTo(...
This is a method to use when writing a business rule, that evaluates an event, for example when the user goes inactive.
If you still want to go for the scheduled approach, I would recommend that you create a Flow that does this. It can either be triggered when the event happens (user goes inactive), or at a schedule (define specific date/time trigger).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2024 12:39 AM
Hello @sravya vemula ,
You can easily achieve this requirement with the help of Business Rules.
I would suggest create a new After Update BR on [sys_user] table, with script as below -
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('incident');
gr.addQuery('state', '6')//resolved
gr.addQuery('assigned_to',current.sys_id);
gr.query();
while(gr.next()){
gr.assigned_to = current.manager;
gr.update();
}
})(current, previous);
If my answer solves your issue, please mark it as Accepted and Helpful based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2024 02:06 AM
Thank you for your response Vrushali. The requirement has been changed. Thanks 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2024 06:47 AM
Hi @sravya vemula ,
You can write a simple schedule job to run daily as shown below,
This checks for all the incident which are closed, resolved or cancelled and Check for assigned to user is active or not.
var gr = new GlideRecord('incident');
gr.addEncodedQuery('stateIN6,7,8');
gr.addQuery('assigned_to.active', false);
gr.query();
while (gr.next()) {
// gs.info('Assignment manager ' + gr.assignment_group.manager + 'Incident ' + gr.number);
gr.assigned_to = gr.assignment_group.manager;
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.update();
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang