Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

populate appovers list in custom field on RITM

Ash41
Kilo Sage

Hi Team, 

 

I want to populate Approvers list in custom field on RITM. I have wrote below BR on RITM table after- insert/update.

Users are not populating, not sure what's wrong. custom field is glide list type.

 

Condition: current.approval.changesTo('requested')

 

 

(function executeRule(current, previous /*null when async*/) {
	var gr = new GlideRecord('sysapproval_approver');
	gr.addQuery('sysapproval', current.sys_id);
	gr.query();
	var myString='';
	if(gr.hasNext()){
		while(gr.next()){
			myString = myString +gr.approver+',';
			gs.log(current.number+' Inside while loop Approval List ='+myString);
		}
		myString=myString.slice(0, -1);
		gs.log(current.number+' Outside while loop Approval List ='+myString);	
		current.u_approvers=myString;
		gs.log(current.number+' Outside while loop current.u_approvers ='+current.u_approvers);
		current.update();
	}
})(current, previous);

 

 

 

1 ACCEPTED SOLUTION

@Ash41 

 

1) In the BR condition you can add a condition (first tab where we mentioned the condition in builder)

-> u_approvers is empty

2) please make BR to before-> insert/update

3) Remove current.update()

 

current.update() is fine for after insert but creates problem for after update

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

View solution in original post

10 REPLIES 10

Prince Arora
Tera Sage

@Ash41 

 

I have gone through from the code and it looks good to me.

Please perform below steps/checks:

1) Can you remove the condition from the BR and update some worknotes in the RITM and check whether it updates the List field as our condition describes the changesTo, if the state is already set to "requested", it will not execute

Please remove and check we will modify the condition later or you can add condition as "u_approvers is Empty"; 

2) Please make sure, you have used the correct backend value of your custom field on RITM (u_approvers)

3) It is not a best practice to use "current.update()" in after-update BR (we will take care of this later once our logic will work)

 

Hi Prince,

 

1) Can you remove the condition from the BR and update some worknotes in the RITM and check whether it updates the List field as our condition describes the changesTo, if the state is already set to "requested", it will not execute

Please remove and check we will modify the condition later or you can add condition as "u_approvers is Empty"; 

- Tried this it is working, added one condition on 3rd line state is requested. Want to remove current.update

(function executeRule(current, previous /*null when async*/) {
	var gr = new GlideRecord('sysapproval_approver');
	gr.addQuery('sysapproval', current.sys_id);
	gr.addQuery('state','requested');
	gr.query();
	var myString='';
	if(gr.hasNext()){
		while(gr.next()){
			myString = myString +gr.approver+',';
			gs.log(current.number+' Inside while loop Approval List ='+myString);
		}
		myString=myString.slice(0, -1);
		gs.log(current.number+' Outside while loop Approval List ='+myString);	
		current.u_approvers=myString;
		gs.log(current.number+' Outside while loop current.u_approvers ='+current.u_approvers);
		current.update();
	}
})(current, previous);

 

@Ash41 

 

1) In the BR condition you can add a condition (first tab where we mentioned the condition in builder)

-> u_approvers is empty

2) please make BR to before-> insert/update

3) Remove current.update()

 

current.update() is fine for after insert but creates problem for after update

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

Everything worked, thank you! 🙂