Assistance Required for Updating Custom Field without refresh in Incident Record via Business Rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2024 08:15 AM
Hi Team,
When adding or removing affected CIs in an Incident record, I want a custom field named "List of Associated CIs" to be automatically updated with the list of affected CIs along with their total count. Could you please guide me on how to implement this functionality using a Business Rule in ServiceNow?
Note: One part of my implementation is working correctly. When affected CIs are added, the correct counts and CI names are displayed in my custom field. However, during the removal of affected CIs, the custom field does not get updated as expected.
I kindly request you to review my script below and make the necessary modifications. Your assistance would be greatly appreciated!
Below is my Code:
Business Rule
When to run: After
Insert: checked
Update: checked
Table: task_ci (CIs Affected)
Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2024 03:38 AM
Hi @MihirG ,
Just create one business rule and use below script. It will work for all the scenarios.
(function executeRule(current, previous /*null when async*/ ) {
var taskCount = new GlideAggregate('task_ci');
taskCount.addQuery('task', current.task);
taskCount.addAggregate('COUNT');
taskCount.query();
if (taskCount.next()) {
var gr2 = new GlideRecord('incident');
gr2.get(current.task);
gr2.u_list_of_associated_cis = "Total Counts: " + taskCount.getAggregate('COUNT');
gr2.update();
}
})(current, previous);
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------