- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 10:58 PM
Hi Team,
In incident table how to auto change assignment group back to previous group after 5 min if no update.
Regards,
Tharun
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 11:06 PM
Hi @Tharun13
Use below code, I have tested it. It will work now.
gs.sleep(5 * 1000 * 60);
var dur = new GlideDuration();
dur.setValue(current.sys_created_on);
var gdt = new GlideDateTime(); //Always UTC +0
var duration2 = new GlideDuration();
duration2.setValue(gdt.getValue());
var answer = duration2.subtract(dur);
if (answer.getDisplayValue().split(' ')[0] >= 5) {
var incGR = new GlideRecord('incident'); // change table name
incGR.addQuery('sys_id', current.sys_id);
incGR.query();
if (incGR.next()) {
var gr1 = new GlideRecord("sys_audit");
gr1.addQuery("tablename", "incident"); // change table name
gr1.addQuery("documentkey", incGR.sys_id);
gr1.addQuery("fieldname", "assignment_group");
gr1.orderByDesc("record_checkpoint");
gr1.setLimit(1);
gr1.query();
if (gr1.next()) {
gs.log('old group' + gr1.oldvalue);
current.assignment_group = gr1.oldvalue;
current.setWorkflow(false);
current.update();
}
}
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 11:15 PM
Hi
Create an after update/insert business rule. Apply gs.sleep(5*1000*60) and check if the sys_updated_on is more than 5 mins ago. If yes, then use previous.assignment_group to set it to the Assignment Group.
Thanks
Deepak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 11:17 PM
Hi Deepak,
Please provide the business rule script.
Regards,
Tharun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 11:42 PM
// Delay execution to ensure it runs 5 minutes after the record was updated
gs.sleep(5 * 1000 * 60); // 5 minutes delay
// Check if the record's sys_updated_on timestamp is more than 5 minutes old
var timeDifference = new GlideDateTime().getNumericValue() - current.sys_updated_on.getGlideObject().getNumericValue();
// Check if the time difference exceeds 5 minutes (300,000 milliseconds)
if (timeDifference > 300000) {
// Set the assignment group back to the value from the previous state
current.assignment_group = previous.assignment_group;
current.update(); // Save the record with the updated assignment group
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 12:20 AM
Hi Deepak,
not working below script.
Regards,
Tharun