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.

Not able to blank out choice field using updateMultiple

Muthu Ganesh
ServiceNow Employee
ServiceNow Employee

On a choice type field, record by record update (to blank) works. But updateMultiple doesn't blank outs the value but retains the previous value.

Ex:

var gr = new GlideRecord('table');
gr.addQuery('sys_id', 'IN', 'sysId1,sysId2');

gr.setValue('choice_field', '');
gr.updateMultiple();

doesn't work

 

But the following works fine

var gr = new GlideRecord('table');
gr.addQuery('sys_id', 'IN', 'sysId1,sysId2');
gr.query();
while(gr.next()){
gr.setValue('choice_field','');
gr.update();
}

 

Do I miss anything here?

1 ACCEPTED SOLUTION

Muthu Ganesh
ServiceNow Employee
ServiceNow Employee

Hi Alok,

 

Thanks for the reply. For updateMultiple - gr.query() maybe optional.

 

I tried the below and it worked:

var gr = new GlideRecord('table');
gr.addQuery('sys_id', 'IN', 'sysId1,sysId2');

gr.setValue('choice_field', 'NULL');  - empty string doens't nulfiy the choice field
gr.updateMultiple();

 

Looks like record by record and update multiple works differently if we try to blank out the choice field by empty string.

View solution in original post

2 REPLIES 2

Alok Das
Tera Guru

Hi Muthu,

You missed to add

gr.query();

your updated script would be:

var gr = new GlideRecord('table');
gr.addQuery('sys_id', 'IN', 'sysId1,sysId2');
gr.query();
gr.setValue('choice_field', '');
gr.updateMultiple();

 

Also you can refer to the below link for more details on updatemultiple() function

https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_GlideRecord-updateMultiple

Please mark my answer correct/helpful based on the impact.

Regards,

Alok

Muthu Ganesh
ServiceNow Employee
ServiceNow Employee

Hi Alok,

 

Thanks for the reply. For updateMultiple - gr.query() maybe optional.

 

I tried the below and it worked:

var gr = new GlideRecord('table');
gr.addQuery('sys_id', 'IN', 'sysId1,sysId2');

gr.setValue('choice_field', 'NULL');  - empty string doens't nulfiy the choice field
gr.updateMultiple();

 

Looks like record by record and update multiple works differently if we try to blank out the choice field by empty string.