Business rule to copy fields from parent incident to child is not working

Mark Weber2
Tera Contributor

I have created a before insert / update business rule to copy fields from a parent incident to a new child incident, but the fields are not populating. My code is below:

(function executeRule(current, previous /*null when async*/) {
//Get parent incident
var gr = new GlideRecord("incident");
gr.addQuery("parent_incident", current.sys_id());
gr.query();
gs.addInfoMessage("parent incident = " + current.sys_id); //for testing

// Setting values to match parent
gr.setValue("cmdb_ci", current.cmdb_ci);
gr.setValue("category", current.category);
gr.setValue("subcategory", current.subcategory);
gr.setValue("assignment_group", current.assignment_group);
gr.setValue("impact", '3');
gr.setValue("urgency", '3');
gs.addInfoMessage("cmdb ci = " + cmdb_ci);
gs.addInfoMessage("current cmdb ci = " + current.cmdb_ci);
gr.update();

})(current, previous);

 

Any help is greatly appreciated! Thanks!

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

first, I would make it an after BR instead of before br. and make a few changes to your script. You won't see this part from the script, but you had a () after current.sys_id, which you don't need, and then a couple of other changes there as well.

(function executeRule(current, previous /*null when async*/) {
  //Get parent incident
  var gr = new GlideRecord("incident");
  gr.addQuery("parent_incident", current.sys_id);
  gr.query();
  gs.addInfoMessage("parent incident = " + current.sys_id); //for testing
  while (gr.next()) {
    // Setting values to match parent
    gr.setValue("cmdb_ci", current.cmdb_ci);
    gr.setValue("category", current.category);
    gr.setValue("subcategory", current.subcategory);
    gr.setValue("assignment_group", current.assignment_group);
    gr.setValue("impact", '3');
    gr.setValue("urgency", '3');
    gs.addInfoMessage("cmdb ci = " + cmdb_ci);
    gs.addInfoMessage("current cmdb ci = " + current.cmdb_ci);
    gr.update();
  }
})(current, previous);

View solution in original post

4 REPLIES 4

Jon Barnes
Kilo Sage

first, I would make it an after BR instead of before br. and make a few changes to your script. You won't see this part from the script, but you had a () after current.sys_id, which you don't need, and then a couple of other changes there as well.

(function executeRule(current, previous /*null when async*/) {
  //Get parent incident
  var gr = new GlideRecord("incident");
  gr.addQuery("parent_incident", current.sys_id);
  gr.query();
  gs.addInfoMessage("parent incident = " + current.sys_id); //for testing
  while (gr.next()) {
    // Setting values to match parent
    gr.setValue("cmdb_ci", current.cmdb_ci);
    gr.setValue("category", current.category);
    gr.setValue("subcategory", current.subcategory);
    gr.setValue("assignment_group", current.assignment_group);
    gr.setValue("impact", '3');
    gr.setValue("urgency", '3');
    gs.addInfoMessage("cmdb ci = " + cmdb_ci);
    gs.addInfoMessage("current cmdb ci = " + current.cmdb_ci);
    gr.update();
  }
})(current, previous);

Hi John, 

Hoping you might have some suggestions. 

We are experiencing the same issues where an Affected CIs / Impacted Service / cmdb_ci updates are not showing in the child record.  

 

I tried creating a Business Rule so that when we manually update the Parent incident, it also appears in the Child Incident.  

 

find_real_file.png

We have also activated the Parent Incident field in the related records.  

find_real_file.png

Hi John,

When I'm changing the incident state to "On-Hold", the reason provided is being copied to child incidents from parent incident, but when I select reason as "Pending Vendor", it does not copy the fields(Vendor and Vendor Ticket Open Date) as colored yellow in color. What should I add in Business Rule?

find_real_file.png

Thank you

Best,

Pranav Patel

Mark Weber2
Tera Contributor

That's it, thanks!