Scheduled job to update the state of change record based on Incident Caused By Change field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 03:07 AM
Hello!
We have a requirement where once a change request is closed, if we receive any incident caused by this change ( within 30 days of the change closure) and same is updated on the "Incident Caused By Change" related list of that change then the "state" of that change should be automatically updated from "Successful" to "Successful with issues".
I am trying to achieve this by creating a scheduled job on the incident table but I am stuck on a use case where a single change has many linked Incidents. How do I make sure that the change record that is already updated gets skipped in the next iteration?
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 04:45 AM
An async business rule may be better placed for this rather than a scheduled job.
and a script of
(function executeRule(current, previous /*null when async*/) {
var changeRec = current.getElement('caused_by').getRefRecord();
if(!changeRec.isValidRecord())
return;
changeRec.setValue('close_code' , 'successful_issues');
changeRec.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 05:22 AM
Hi @Swati36 ,
Please try below solution
I created scheduled job which runs on 29 on every month you can change it as per your requirements and add below script
var gr = new GlideRecord('change_request');
gr.addQuery('active', 'true');
gr.addQuery('state', 3); //closed
gr.query();
while (gr.next()) {
var incGr = new GlideRecord('incident');
incGr.addQuery('caused_by', gr.sys_id);
incGr.query();
while (incGr.next()) {
incGr.setValue('work_notes', 'Successful with issues');
incGr.update();
}
gr.setValue('work_notes', 'Successful with issues');
gr.update();
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 04:59 AM
Hello @Swati36 ,
i run below script in Background and its worked for me ,include it on scheduled script .