Update multiple records with different values for the same field

hardikparpelli
ServiceNow Employee
ServiceNow Employee

I want to update the field 'busines_criticality' of table 'cmdb_ci_service_calculated' for multiple records with different values.

 

GlideRecord update works fine. But I have to do it in a loop. And this is time consuming.

 

Following is my snippet:

 

var gr = new GlideRecord('cmdb_ci_service_calculated');
gr.addEncodedQuery('nameSTARTSWITHtest');
gr.query();

gs.info(gr.getRowCount());

var buscric = new global.ServiceBusinessCriticality();     //custom script that is used to get the value

while(gr.next()){
	gr.setValue('busines_criticality', buscric.get(gr.getValue('name'));
	gr.update();
}

 

 

Is there a way to use GlideRecord updateMultiple?

GlideRecord updateMultiple is not working as required in this case.

 

Plan is to run this in background. But is it possible to use updateMultiple in this case?

3 REPLIES 3

AJ63
Tera Expert

Hi @hardikparpelli 

 

if you are having issue with time, you can run script in background via FIX SCRIPT so that it would be able to run when system gets time to run and perform. Also, you can try setWorkflow(false) so that nothing else would run unless you require to run BRs and such..

 

let me know if this help

 

Thanks!--AJ

hardikparpelli
ServiceNow Employee
ServiceNow Employee

I know we have the option to run in background. But is it possible to use updateMultiple?

OlaN
Giga Sage
Giga Sage

Hi,

In most cases updateMultiple() method is a valid option (should not be used when setting price or currency fields though).

In this case, it seems you want to set different values on your records,
depending on what result you get back from this method: 

buscric.get(gr.getValue('name')

 

So in this particular scenario, it seems not possible to use updateMultiple, since you are not setting the same value on your records.