updateMultiple() doesn't update system fields like sys_updated_on or sys_mod_count

Max Nowak
Kilo Sage

Hi,

I'm using GlideRecord updateMultiple() in a usecase where I might have to update >100k records. My problem is that a 3rd party system periodically scans the table via the table API, creates a delta based on sys_updated_on, and moves the data into some sort of data warehouse (it's out of scope for me, I only know that the mechanism relies on sys_updated_on and possibly sys_mod_count).

 

Due to this circumstance, it's important that, at worst, sys_updated_on gets updated when I update records. The more efficient updateMultiple() doesn't seem to do that, though.

 

Is there any way I could enable the updating of system fields for updateMultiple(), or, alternatively, is there any reason I simply couldn't update the sys_updated_on manually, like so:

 

var customTableGr = new GlideRecord('u_custom_table');
customTableGr.addEncodedQuery('active=true');

customTableGr.setValue('u_random_checkbox', true);
customTableGr.setValue('sys_updated_on', new GlideDateTime().getValue());

customTableGr.updateMultple();

 

Thanks in advance for your help,

Max

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Try to add GlideRecordObject.autoSysFields(false); in there too

var customTableGr = new GlideRecord('u_custom_table');
customTableGr.addEncodedQuery('active=true');

customTableGr.setValue('u_random_checkbox', true);
customTableGr.setValue('sys_updated_on', new GlideDateTime().getValue());
customTableGr.autoSysFields(false);
customTableGr.updateMultple();

 

-Anurag

Simon Christens
Kilo Sage

sys_updated_on is automatically set so theres no need to try and set it through the GlideRecord

All system fields (sys_created_on, sys_updated_on, sys_updated_by etc) is automatically set unless the method the below method is used

.autoSysFields(false);

I just tested it on my own instance and updateMultiple() sets the sys_updated_on to the exact time the update happened.

SimonChristens_0-1683620432456.png

 

If you still struggle then theres a couple of other possibilities.

1.

Try use setWorkflow(false) before the updateMultiple() *CAUTION*
This will ensure that BRs etc does not run - but if you need something to run on these updates then try 2.

2.

Use setforceUpdate(true) like:

while(customTableGr.next()){

      customTableGr.setForceUpdate(true);
      customTableGr.update();
}

This will go through each record and force a database update without having to update any fields in the record.
It also gives the system time to run BRs etc between each update.
Depending on the amount of rules that runs in the background of the updates.

Hm, that's interesting. Thanks for that information. I might need to do some more testing, because you're right, if I execute updateMultiple in a background script, sys fields will be set.

 

Still, there seems to be a problem, because I have lots of records where I know that the field changed, but the sysfields weren't set. I'll do some digging and report back.

This might indeed require some troubleshooting.
I do not know what runs when these records is updated but as an example when using updateMultiple()

It starts a mass update and if for ex a business rule triggers (maybe async BR) that triggers a setWorkflow(false) in a script include etc then the mass update will suddently stop running BRs and therefore stop updating the sys fields.

Theres a huge amount of different possibilities why this happens and it can be a pain to figure out.

With using while loop then you will give the system time to do whats needed but it also increases the execution time quite alot possibly (again it depends on the amount of rules that runs on update)