How to fill a field with all assignment groups that were on the incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 09:37 AM
Hi,
I have the field u_group_assignment_history of type List to sys_user_group. Im trying populate this field with all assignment groups that were on the incident. The problem that I have is that when the user create the incident, this field is not populated with the current assignment group. Only when the user changes the assignment group the functionality is working and the field populates with the previous and current assignment group but I need that this field will be populated with the current assignment group as soon as the user create the incident.
(function executeRule(current, previous /*null when async*/) {
if(current.u_group_assignment_history.toString().includes(previous.assignment_group.toString()))
current.u_group_assignment_history=current.u_group_assignment_history.toString()+','+current.assignment_group.toString();
else
current.u_group_assignment_history=current.u_group_assignment_history.toString()+','+previous.assignment_group.toString()+','+current.assignment_group.toString();
// Add your code here
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 10:03 AM
Hi Alon,
Can you try:
(function executeRule(current, previous /*null when async*/) {
var groupsHistory = current.u_group_assignment_history.toString();
// '.includes' works on arrays so we check if previous is contained in current
// if(current.u_group_assignment_history.toString().includes(previous.assignment_group.toString()))
if (groupsHistory.indexOf(previous.assignment_group.toString()))
current.u_group_assignment_history=current.u_group_assignment_history.toString()+','+current.assignment_group.toString();
else
current.u_group_assignment_history=current.u_group_assignment_history.toString()+','+previous.assignment_group.toString()+','+current.assignment_group.toString();
// Add your code here
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 10:38 AM
@Bert_c1 its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 10:54 AM
Yes,
the "if" should be
if (groupsHistory.indexOf(previous.assignment_group.toString()) >= 0)
But then below we see Saurabh has tested your original logic it seems.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 11:12 AM
@Bert_c1 i think the problem was with order of other BR