- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2024 10:15 AM
This is something I'm just curious about as I'm creating a scheduled script that updates records. I'm trying to make sure I'm not touching records if it's unncessary, but what does actually happen if you do a query with an updateMultiple and one of the records either partially or fully has the updated values?
What happens with my script if it runs and is updating 4 fields, but 2 of the 4 fields already match what I have set? Is there a performance impact, or is the Glide Update smart enough to tell that those updates aren't needed and ignores them?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2024 10:35 AM - edited ‎07-16-2024 10:36 AM
When using ServiceNow's updateMultiple() method to update records, the system does not automatically verify that the current values in the fields match the new values being set. It just updates the fields with the provided values, whether or not they have changed. This means that if you use updateMultiple() in a query and some of the fields already have the appropriate values, those fields will be written to the database.
There could definitely be a performance issue; even if you don't have anything to update, it will still update the record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2024 10:29 AM
Those records updates with same value, and there wont be performance issue if the records are minimal in number.
But instead of querying all the records , if you want to update multiple records, you can filter those records by adding encoded query.
For example, if you want to set state to 2 and out of 4 records 2 records are already having that state, you can add query as below
gr.addEncodedQuery(state!=2^numberININC0190439,INC0190440,INC0190441,INC0190441');
Please mark helpful if i answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2024 11:07 AM
This is ultimately what I'm trying to do. For my current use case, it may require a more aggressive initial pass to make sure everything is aligned and there aren't these partial updates, but afterwards what you've suggested, I think, will work. Thanks for the input!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2024 11:15 AM - edited ‎07-16-2024 11:16 AM
Apologies for the double reply, but I do have an additional question:
If I can't get my query to work in such a way that I only target the records I want, is it possible (and advisable) to do a check within my script itself? For example:
while (gr.next){
if (gr.field1 != "A" && gr.field2 != "B" || gr.field3 == "C")
{
gr.field1 = "A";
gr.field2 = "B";
gr.field3 = "D";
gr.update();
}
else
{
// Do nothing.
}
Would something like this work? I figure in this case as it's checking each record, it would only be an Update, but I imagine that the trade-off would be it's still checking each record in the original query, but only performing updates as required.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2024 01:42 AM
Yes , it will work. But it will be a lengthy code if there are many records and also time consuming.
As we have out of the box query , you can use it before entering to while loop.