
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 03:44 AM
We have a requirement in the company to sync certain fields down from a Parent Incident to each of its Child Incidents. This are the Business Service, Assignment Group and Assigned To.
Little wrinkle to that is you can only select an Assigned To that is in the Assignment Group chosen.
So I've had a Business Rule in for a while that runs After Update of the Parent Incident, and it will check the Child to make sure things match.
However, it's become clear recently that this isn't working correctly, and in fact every single time a worknote or comment are added to the Parent, or another INC is linked to the Parent, then every single Child Incident is getting their Assigned To wiped and re-added - even on Closed tickets, which is then triggering closed emails and surveys again.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 03:52 AM - edited 07-24-2024 03:53 AM
HI,
You cannot use childIncidents.assignment_group before .next() as it will not have any value to compare
Try this
(function executeRule(current, previous /*null when async*/) {
var childIncidents = new GlideRecord('incident');
childIncidents.addQuery('parent_incident', current.sys_id);
childIncidents.query();
while (childIncidents.next()) {
if (childIncidents.assignment_group != current.assignment_group) { //you cannot use this before .next()
childIncidents.assigned_to = '';
childIncidents.assignment_group = current.assignment_group;
childIncidents.update();
childIncidents.assigned_to = current.assigned_to;
childIncidents.update();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 03:58 AM - edited 07-24-2024 05:18 AM
In your case it would be better to move to the flow designer. It's easy to use and shows exactly what you are doing. For people that don't are magicians with scripts, that often the best way to get what they need.
Trigger it on 'assignment group change, assigned to change or business service change' and do a look up to all incidents where the parent = the record triggered. If nothing found, end flow. Else: for each found incident update the fields to that of the parent.
For your BR: trigger it the change of any of the three fields you need synced and then use this script:
var childIncident = new GlideRecord('incident');
childIncident.addQuery('parent_incident',current.getUniqueValue()); // validate that this is indeed the correct field
childIncident.addQuery('active',true);
childIncident.next();
while childIncident.next(){
if(childIncident.assigned_to != current.assigned_to){
childIncident.assigned_to = current.assigned_to;
}
if(childIncident.assignment_group != current.assignment_group){
childIncident.assignment_group = current.assignment_group;
}
if(childIncident.business_service != current.business_service){
childIncident.business_service = current.business_service;
}
childIncident.update();
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 04:00 AM - edited 07-24-2024 04:03 AM
Hi @StewartF,
So a couple of observations here.
Firstly, add some filter conditions so the business rule only runs if one of the 3 fields you mentioned (Business Service, Assignment Group and Assigned To) change, thus make sure it doesn't trigger after every update.
See first screen shot below.
Secondly, I would also add a clause to ensure you're only checking with 'active' incidents (Non closed tickets).
Question - do you also want to consider if the Child Incidents are active as well?
You'll need to add a line similar to:
childIncidents.addQuery('active', true); // Checking for active child incidents only (Not all including closed)
Screen shot:
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie