How to add to a List field all assignment groups that were on the incident

Alon Grod
Tera Expert

I have the field u_assignment_history of type List on the incident table. I have a requirement to write a Business Rule on the incident table on insert and update that whenever the field assignment_group (reference to sys_user_group table) changes, I need to insert into the u_assignment_history list the previous and the current group. Basically the goal of the Business rule is to show all groups that were the assignment group on the current incident. How can I achieve that?

1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hello Alon,

 

1.You can write before business rule with below condition.

 

VishalBirajdar7_0-1693803975875.png

 

2. Script

(function executeRule(current, previous /*null when async*/ ) {

    var agHis = current.u_assignment_group_history.toString();
    if (agHis) {

        current.u_assignment_group_history = current.u_assignment_group_history.toString() + ',' + current.assignment_group.toString();

    } else {
/* Set assignment group history for first time */
        current.u_assignment_group_history = current.assignment_group.toString();
    }

})(current, previous);

 

Also its better to set assignment group history field to be read-only.

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

2 REPLIES 2

Sunny3008
Tera Guru

Hello @Alon Grod ,

 

1. You can achieve this by writing before update business rules on the incidents table. use the following script.

 

Script:

(function executeRule(current, previous /*null when async*/) {

	if(current.u_assignment_history.toString().includes(previous.assignment_group.toString()))
		current.u_assignment_history=current.u_assignment_history.toString()+','+current.assignment_group.toString();
	else
		current.u_assignment_history=current.u_assignment_history.toString()+','+previous.assignment_group.toString()+','+current.assignment_group.toString();

	// Add your code here

})(current, previous);

2. Another way to achieve this is to write on change client script on assignment group.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var temp=g_form.getValue('u_assignment_history').toString+','+newValue;
   g_form.setValue('u_assignment_history',temp);


   //Type appropriate comment here, and begin script below
   
}

  Please mark this as the correct answer and helpful if it is resolved, or mark this helpful if this helps you to reach towards solution.

Vishal Birajdar
Giga Sage

Hello Alon,

 

1.You can write before business rule with below condition.

 

VishalBirajdar7_0-1693803975875.png

 

2. Script

(function executeRule(current, previous /*null when async*/ ) {

    var agHis = current.u_assignment_group_history.toString();
    if (agHis) {

        current.u_assignment_group_history = current.u_assignment_group_history.toString() + ',' + current.assignment_group.toString();

    } else {
/* Set assignment group history for first time */
        current.u_assignment_group_history = current.assignment_group.toString();
    }

})(current, previous);

 

Also its better to set assignment group history field to be read-only.

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates