Update Child with Parent 'Assigned To' I know it's been covered but please read.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2013 06:06 AM
We have a business rule that closes incidents when a parent incident is closed however I would like the Assigned To field to be populated in the child record once the parent incident status changes to 8, currently it is not populated. The BR is very simple:-
Run on the Incident table at server and after. Insert and Update are ticked.
Condition is - current.isValidRecord()
Script is - //
// Close any child incidents
//
if (current.active.changesTo(false)) {
closeRelatedTasks(current);
}
I have played around with many changes but cannot get it to work, does anyone have a suggestion for me as none of the suggestions posted here appear to work either.
The parent field on our incident record is a reference field back to task.
TIA
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2013 08:16 AM
Try this, it should query the table locate any child incidents and update them before they get closed.
The condition is optional feel free to chop and change
Condition: current.isValidRecord() && current.u_related_incidents > 0
//if status changes to 8 find all the child incidents otherwise go straight to closeRelatedTasks
if (current.state.changesto(8)){
var inc = new GlideRecord('incident');
inc.addQuery('sys_id', current.u_parent_incident);
inc.query();
while (inc.next()) {
inc.assigned_to = current.assigned_to; //Update the child incidents assigned to field and then close them
inc.update();
}
}
closeRelatedTasks(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2013 02:23 AM
It looks like I have another BR that has a higher precedence, I disables that but your suggested rile didn't work.
The rule I disabled is:-
//
// Close any tasks that are related to the current task
//
function closeRelatedTasks(me) {
var task = new GlideRecord("task");
task.addQuery("parent", "=", me.sys_id);
task.query();
while (task.next()) {
if (task.sys_class_name == 'incident')
//NYK closeIncident(task.sys_id, me.number);
NYKcloseIncident(task.sys_id, me);
else if (task.sys_class_name == 'problem')
closeProblem(task.sys_id, me.number);
else if (task.sys_class_name == 'change_request')
closeChange(task.sys_id, me.number);
else {
task.active.setValue(false);
task.update();
gs.print("Task " + task.number + ' closed based on closure of task '+me.number);
}
}
task.close();
}
function closeProblem(myID, fromNumber) {
var problem = new GlideRecord('problem');
if (problem.get('sys_id', myID)) {
var msg = "Problem " + problem.number + ' closed based on closure of task '+ fromNumber;
problem.problem_state.setValue(4);
var notes = problem.close_notes.getDisplayValue();
notes = notes + '\n' + msg;
problem.close_notes.setValue(notes);
problem.update();
gs.print(msg);
}
}
function closeIncident(myID, fromNumber) {
var incident = new GlideRecord('incident');
if (incident.get('sys_id', myID)) {
var msg = "Incident " + incident.number + ' closed based on closure of task '+ fromNumber;
gs.print(msg);
incident.incident_state.setValue(7);
incident.active.setValue(false);
incident.comments = msg;
incident.update();
}
}
function NYKcloseIncident(myID, fromTask) {
var incident = new GlideRecord('incident');
if (incident.get('sys_id', myID)) {
var msg = "Incident " + incident.number + ' closed based on closure of task '+ fromTask.number;
gs.print(msg);
setIncidentState(incident, fromTask);
incident.active.setValue(false);
incident.comments = msg;
incident.close_notes = fromTask.close_notes;
incident.update();
}
}
// fromTask is the original task that is being closed
// incident is the related incident that should be closed
// If fromTask is an incident then we want to use the incident_state from that task to close the incident
// if fromTask is NOT an incident (problem, change, etc) then we will use the standard close code (8)
function setIncidentState(incident, fromTask) {
if (fromTask.sys_class_name != 'incident') {
// use standard closure code
incident.incident_state = 8;
return;
}
// copy the closure code from the original incident
var fromIncident = new GlideRecord('incident');
fromIncident.get(fromTask.sys_id);
incident.incident_state = fromIncident.incident_state;
return;
}
function closeChange(myID, fromNumber) {
var rfc = new GlideRecord('change_request');
if (rfc.get('sys_id', myID)) {
var msg = "Change " + rfc.number + ' closed based on closure of task '+ fromNumber;
var notes = rfc.close_notes.getDisplayValue();
notes = notes + '\n' + msg;
rfc.close_notes = notes;
rfc.active = false;
rfc.update();
gs.print(msg);
}
}
Can you suggest how I modify the section starting 'function closeIncident' or 'function NYKcloseIncident' to update the assigned to, I have tried a couple of thing but nothing works.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2013 12:57 AM
Thanks for the input Neil.
I tried this as was and it didn't work, however I tried it again with the original condition and it closed the incident but did not populate the assigned to field.
Does it make and difference that the assigned to field is a reference field on the sys_user table?
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2013 02:20 AM
It shouldn't make any difference, when you copy a value from one reference field to another your copying the record ID
There is a Update child incidents BR that runs already on this table, it may be worthwhile inserting the assigned to field change in that rule instead of writing a new one.
Note: This rule runs if a incident is resolved