Copy Parent incident fields to Child incident field -- Issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2022 08:32 PM - edited 11-20-2022 08:38 PM
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2022 09:15 PM
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
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2022 09:25 PM
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