setLimit method while using UpdateMultiple() on tables.

VasukiS
Tera Guru

Hi,

 

Why not to use Setlimit method while using updatemultiple.

 

Needs to know why setLimit() is not allowed on updatemultiple() method.

 

I have checked the Servicenow Documentation it has been mentioned as below

Do not use this method with the chooseWindow() or setLimit() methods when working with large tables.

This method sets new values and does not clear existing values. To clear an existing value, use the setValue() method and set the field to null.

 

I need more clarification for this. Couldn't find a y detailed document for this.

 

Share the details if you any idea.

1 ACCEPTED SOLUTION

Animesh Das2
Mega Sage

Hi @VasukiS ,

 

updateMultiple() or deleteMultiple() works on the entire glide query result set. That is why if you see you don't even fetch each record by iterating through the object using 'next()' inside a loop before executing updateMultiple() or deleteMultiple(). You just query and put updateMultiple() or deleteMultiple() since it works like you are telling system to update or delete all the records in the result set at once (not, one by one by looping through each record).

updateMultiple() is also much more efficient than (update()) looping through each record returned from your glide query, retrieving it from the database, setting each value at a time, and saving each record back to the database.

 

As updateMultiple() or deleteMultiple() works on entire result of the glide query by its working mechanism, there is no point of using chooseWindow() or setLimit() before, as those will be just ignored even if you put those before updateMultiple() and deleteMultiple().

 

If this address your question, please mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

View solution in original post

1 REPLY 1

Animesh Das2
Mega Sage

Hi @VasukiS ,

 

updateMultiple() or deleteMultiple() works on the entire glide query result set. That is why if you see you don't even fetch each record by iterating through the object using 'next()' inside a loop before executing updateMultiple() or deleteMultiple(). You just query and put updateMultiple() or deleteMultiple() since it works like you are telling system to update or delete all the records in the result set at once (not, one by one by looping through each record).

updateMultiple() is also much more efficient than (update()) looping through each record returned from your glide query, retrieving it from the database, setting each value at a time, and saving each record back to the database.

 

As updateMultiple() or deleteMultiple() works on entire result of the glide query by its working mechanism, there is no point of using chooseWindow() or setLimit() before, as those will be just ignored even if you put those before updateMultiple() and deleteMultiple().

 

If this address your question, please mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das