aving Event for business rule not triggering notification for additional users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2024 08:26 AM
I'm
(function executeRule(current, previous /* GlideRecord */ ) {
// Get current and previous values of additional_assignee_list
var notYetReceivedNotification = current.getValue('additional_assignee_list');
var receivedNotification = previous.getValue('additional_assignee_list') + ',';
// Remove already notified assignees from the list
notYetReceivedNotification = notYetReceivedNotification.replace(receivedNotification, '');
// Split remaining assignees into an array
notYetReceivedNotification = notYetReceivedNotification.split(',');
// Iterate through the array and queue events for each assignee
for (var i = 0, n = notYetReceivedNotification.length; i < n; i++) {
gs.eventQueue("additional.implementers", current, notYetReceivedNotification[i]);
}
})(current, previous);
having issues with a business rule i created for a event that will trigger a notification for 'additional implementers' on the change task. if a user is added after the change task has been created i need a notification to be sent to those users only.
can anyone help if I'm missing an configurations with the BR itself or the notification.
i provided screen shots below.
than k you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2024 06:21 PM
You would need to split both the previous and current additional assignee list, than filter out from the current assignee list array those items that are in the previous assignee list array and raise the event for the remaining current assignee list array items.
Let's say the original assignee list is A,B,C.
And the current assignee list is A,B,D,E.
Your code attempts to replace A,B,C in A,B,D,E, but A,B,C does not contain A,B,C.
So nothing gets replaced.
I mean it may be that, by chance, when the assignee list is edited and items are only added the original order is preserved and in some cases the code would work.
But you cannot assume this, it is not guaranteed.
That is why you need to turn the values into arrays and work with array items.
Something like:
(function executeRule (previous, current) {
// Get current and previous values of additional_assignee_list
var notYetReceivedNotification = getListAsArray(current.additional_assignee_list);
var receivedNotification = getListAsArray(previous.additional_assignee_list);
// Remove already notified assignees from the list
notYetReceivedNotification = notYetReceivedNotification.filter(notOneOf(receivedNotification));
// Split remaining assignees into an array
// No longer needed: notYetReceivedNotification = notYetReceivedNotification.split(',');
// Iterate through the array and queue events for each assignee
for (var i = 0, n = notYetReceivedNotification.length; i < n; i++) {
gs.eventQueue("additional.implementers", current, notYetReceivedNotification[i]);
}
function getListAsArray (listElement) {
return String(listElement)
// Eliminate leading or trailing spaces so that if the list has
// the form " A, B, C , " the elements will not end up bing
// " A", " B", " C " and " "
// but
// "A", " B", " C ", and ""
.trim()
// Split eliminating spaces from around the delimiter, so that the
// array will look like:
// "A", "B", "C" and ""
.split(/\s*,\s*/g)
// Furtehr sanitize the array removing empty elements, so that the
// array will look like:
// "A", "B" and "C"
.filter(isNotNullAndIsNotEmpty);
}
function isNotNullAndIsNotEmpty (item) {
return item != null && item != '';
}
function notOneOf (itemsToExclude) {
return function (item) {
return itemsToExclude.indexOf(item) < 0;
};
}
})(previous, current);