Behavior of updateMultiple with reference fields in the query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2016 03:55 PM
Hi All,
I am using the updateMultiple() function to perform a mass update of records in a table and am having a bit of trouble. I am hoping someone with more in-depth knowledge of how this function works can help me. The code is as follows:
01 function updateCIs() {
02 var gr = new GlideRecord(MY_TABLE);
03 gr.addEncodedQuery('u_company.nameLIKEAcme^u_descriptionLIKEfirewall')
04 gr.addQuery('u_state', 'pending');
05 gr.query();
06
07 gs.debug("Number of records to be updated: " + gr.getRowCount()); //This returns the correct number of records to be updated
08 gr.u_ci = '58d097aa6f7d120073ccf13f5d3ee499';
09 gr.updateMultiple();
10 }
When I execute this, the records are not updated even though the query is functioning correctly. The log statement in line 7 correctly gives me the number of records to be updated and no error messages are thrown in the log (that I can see).
After some experimentation I found that the issue lies when I am incorporating reference fields in my encoded query. If I replace line 3 with the following code the records are updated successfully:
03'' gr.addEncodedQuery('u_company=7b5f84456f71d20073ccf13f5d3ee4c7^u_descriptionLIKEfirewall')
I initially thought updateMultiple might not work on join queries and that the 03 query is performing a join, while 03'' might not be since it's just querying the sys_id directly. However I tried testing this manually, by navigate to the table through the UI, applying the 03 query, and then shift-selecting the CI field to perform a mass update. This worked.
It just appears I can't seem to update records via my script when trying to dot-walk to reference fields in the encoded query. My question is:
1. Why does one work and not the other?
2. And is there a way for me to re-formulate my encoded query so this does work?
Thanks,
Sid Sonrexa
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2016 09:00 PM
Hi Sid,
Have you tried adding the query in line 4 to the encodedQuery in line 3?
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2016 09:01 PM
It would then be something like:
gr.addEncodedQuery('u_company.nameLIKEAcme^u_descriptionLIKEfirewall^u_state=pending');
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2016 05:38 PM
Hi Berny,
Thanks for the response. I've had to switch to something else and haven't had a chance to revisit this. I will try incorporating "u_state" into the encoded query and see if that makes and difference and let you know the results.
Sid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2016 09:15 PM
You're welcome Sid. Most probably that will fix your problem.
Please keep me posted on how it goes.
Thanks,
Berny