Last active
March 24, 2023 16:32
-
-
Save cmcdevitt/5dfa67980dfdb817c05435952ab79bf7 to your computer and use it in GitHub Desktop.
updateMultiple() and Vulnerability Response or Configuration Compliance and some alternates for large data sets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/no-namespace/c_GlideRecordScopedAPI#r_ScopedGlideRecordUpdateMultiple?navFilter=updatem | |
| So... for VR and CC *** DON'T *** use updateMultiple(). | |
| Why? Becouse: | |
| (1) On Audited tables it acts more like a glide query and does it one at a time with all the overhead | |
| (2) >5000 records seesm to be hard on the Node, so be nice to your Nodes ;) | |
| 3/24/2023 -- True today, but if you are reading this years from now... things might have changed... | |
| */ | |
| //#1 Bite size chunks using the sys_id | |
| // A method in a Script Inlucde | |
| setRTonVITS: function(vgID) { | |
| var pageSize = 1000; | |
| var lastNumber = ""; | |
| var retrievedCount = 0; | |
| do { | |
| var findGroupForVI = new GlideRecord("sn_vul_m2m_vul_group_item"); | |
| findGroupForVI.addQuery("sn_vul_vulnerability", vgID); | |
| if (lastNumber){ | |
| findGroupForVI.addQuery("sys_id", ">", lastNumber); //Important | |
| } | |
| findGroupForVI.setLimit(pageSize); | |
| findGroupForVI.orderBy("sys_id"); //Important | |
| findGroupForVI.query(); | |
| retrievedCount = findGroupForVI.getRowCount(); //Important | |
| while (findGroupForVI.next()) { | |
| lastNumber = findGroupForVI.sys_id; | |
| vit = new GlideRecord('sn_vul_vulnerable_item'); | |
| vit.get(findGroupForVI.sn_vul_vulnerable_item); | |
| vit.setValue("u_deferred_by", vgID); | |
| vit.update(); | |
| } | |
| } while (retrievedCount == pageSize);//Important | |
| }, | |
| /* | |
| Method #2 "PagedGlideRecord" (sn_vul.PagedGlideRecord") -- This Comes with VR so you can just re use it | |
| see: | |
| https://gist.github.com/cmcdevitt/bf6b1c2e0a37b538dfbccf6e183cb0a8 | |
| */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment