Business rule for a count not working properly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 07:55 AM
Hi All,
We have created a custom field for the alert form(em_alert table) called 'Overall Secondary Alerts Count' which should display the total secondary alerts' count.
The count should be updated whenever the secondary alert is tagged.
Used below script in the business rule for that:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 08:02 AM - edited 10-05-2023 08:09 AM
Hi @Shruti08 ,
Please try below script first it will query the secondary alerts related to the current alert and then update the Overall Secondary Alerts Count field on the parent alert.
(function executeRule(current, previous /*null when async*/) {
var secondaryAlertGR = new GlideRecord("em_alert");
secondaryAlertGR.addQuery("parent", current.sys_id);
secondaryAlertGR.query();
var secondaryAlertsCount = 0;
while (secondaryAlertGR.next()) {
secondaryAlertsCount++;
}
var parentAlertGR = new GlideRecord("em_alert");
if (parentAlertGR.get(current.parent)) {
parentAlertGR.u_secondary_alerts_count = secondaryAlertsCount;
parentAlertGR.update();
}
})(current, previous);
Please mark it as solution proposed if it is healpful.
Thanks,
Anand