Copy Parent incident fields to Child incident field -- Issue

Harsha Pandey
Tera Expert

Hi,

 

Please help me with the solution!!!

My requirement is that when we click on 'New' button of 'Child Incident' in the related list of any incident , then parent incident fields like service, service offering, category and many more should get copied to child incident while creating.

I have written a business rule and it is working fine as the fields are getting copied but the issue is if I try to change those field values to something else then it gets saved with the original value like parent. It is not getting saved with any new value. 

It is happening while creating the child incident from new button as well as through OOB UI action 'Create Child Incident' . y

HarshaPandey_0-1669005019807.pngHarshaPandey_1-1669005074626.png

I have written below business rule:

 

When to run: Display
Advanced:

(function executeRule(current, previous /*null when async*/ ) {

var grincident = new GlideRecord("incident");
grincident.addQuery("sys_id", current.parent_incident);
grincident.query();
if (grincident.next()) {
// Setting values to match parent
current.cmdb_ci= grincident.cmdb_ci;
current.category =grincident.category;
current.subcategory=grincident.subcategory;
current.business_service=grincident.business_service;
current.assignment_group =grincident.assignment_group;
current.caused_by = grincident.caused_by;
current.rfc =grincident.rfc;
current.problem_id=grincident.problem_id;
current.short_description=grincident.short_description;
current.service_offering =grincident.service_offering;
current.correlation_id=grincident.correlation_id;
//gs.info('child updated'+ current.number);

}

})(current, previous);

 

Thanks,

Harsha

2 REPLIES 2

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @Harsha Pandey ,

The issue here is due to the business rule running after you update as well . Hence I would suggest you to only run your business rule 'on after' and 'insert' so your business rule will only run after the record is inserted and not updated.

 

You can manage the conditions to run the business rule only when parent is not empty so it will not run for all incidents.

Please mark my answer correct if it helps.

BR,
Nayan

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Hi Nayan,

I have tried with after, before business rules but then it does not run. However I have got the solution.

I added if(current.isNewRecord()) condition at the top of the script.

 

Thanks,

Harsha