How to fill a field with all assignment groups that were on the incident

Alon Grod
Tera Expert

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.

 

Screenshot 2023-09-06 at 19.37.03.png

(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);
7 REPLIES 7

Bert_c1
Kilo Patron

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);

@Bert_c1 its not working

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.

@Bert_c1 i think the problem was with order of other BR