Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to clear list type field in business rule

Nico12
Mega Sage

Hi,

 

I am trying to empty a list type field value in a business rule but gr.fieldname = '';  doesn't seems to work.

 

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

	// Add your code here
	var approvers = [];
	var getApprovers = new GlideRecord('sysapproval_approver');
	getApprovers.addEncodedQuery('source_table=sc_req_item^state=requested^sysapproval=' +current.sysapproval); //only show pending approvals on sc_request and sc_req_item tables
	getApprovers.query();
	while(getApprovers.next()){
		approvers.push(getApprovers.approver.toString());
		var taskValue = getApprovers.getValue('sysapproval');

		var getRitm = new GlideRecord('sc_req_item');
	//getRitm.addQuery('request',current.sysapproval);
	getRitm.addQuery('sys_id', taskValue);
	getRitm.query();
	if(getRitm.next()){

		getRitm.u_approvers = '';
		getRitm.u_approvers = approvers.toString();

		getRitm.update();
	}	
	}

})(current, previous);

 

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Hi,

Try using 
getRitm.setValue('u_approvers', '');

 

Although, you are just setting new values to the list field, you donot need to explicitly empty the field, just remove this line from the above script:

getRitm.u_approvers = '';

 

Best Regards
Aman Kumar

View solution in original post

1 REPLY 1

Aman Kumar S
Kilo Patron

Hi,

Try using 
getRitm.setValue('u_approvers', '');

 

Although, you are just setting new values to the list field, you donot need to explicitly empty the field, just remove this line from the above script:

getRitm.u_approvers = '';

 

Best Regards
Aman Kumar