- Stefan Hulls
Relink Incidents from a Problem to a Change

Prerequisites if you like to try it:
You already have an ITPR demo account. If not, you can easily request one with demo data.
You already signed up for a techwork automator demo account. If not, goto the registration blog post.
Business case:
Having Incidents linked to a Problem makes sense for the team investigating the root cause of a Problem because Incidents may provide important information. By the time the Problem is solved all related Incidents should have been completed – a workaround provided by the problem record should have helped.
Implementing the solution for the problem in the production environment is often done via a Change. Therefore a Change will be linked to the Problem.
An Incident can be linked to a Problem or to a Change. For the Change manager and the Change team it might be of importance to have the Incidents linked to the Change.
With a short automator script the Incidents are relinked as soon as a Change gets related to the Problem.
mergeAudit(problem);
if (problem.audit_is_changed_change && problem.audit_new_change) {
foreach(req in problem.requests) {
update('requests', req.id, {
problem: null,
change_id: problem.change.id,
internal_note: '``` -- Relinked from Problem: '
+ problem.id + ' to Change: ' + problem.change.id + ' --```'
});
}
update('problems', problem.id, {
note: '``` -- Requests relinked to Change: '
+ problem.change.id + ' --```'
});
}
What it does:
The script looks if a Change is newly linked to the Problem. If yes each Incident (‘requests’) gets updated with a ‘null’ Problem value. The link to the problem is now cut. The new link created via the change_id relinks the Incident to the Change. To make it easier for the IT staff an internal note is added to each Incident indicating that the Incident has been ‘Relinked’ from the Problem to the Change. The Problem gets a note too.
Any variation is possible. For some organisations it might be of value to relink only open Incidents to the Change, for others all.
The script with comments:
//get Audit data of the Problem that is being updated
mergeAudit(problem);
//New change linked to the problem?
if (problem.audit_is_changed_change && problem.audit_new_change) {
//run through all Incidents(request) linked to the problem
for(let req of problem.requests) {
//update each request. Set the problem link to 'null' and relate
//each request to the change and add an internal note
update('requests', req.id, {
problem: null,
change_id: problem.change.id,
internal_note: '``` -- Relinked from Problem: '
+ problem.id + ' to Change: ' + problem.change.id + ' --```'
});
}
//update the problem with a note too
update('problems', problem.id, {
note: '``` -- Requests relinked to Change: '
+ problem.change.id + ' --```'
});
}
Interesting to note:
The Internal_note field is updated of each of the Incidents, therefore the user does not see the note in Self Service.