Update multiple records with different values for the same field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 11:46 AM - edited 06-01-2024 08:41 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 01:47 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2024 08:40 AM
I know we have the option to run in background. But is it possible to use updateMultiple?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2024 10:28 AM
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.