Last active
October 11, 2021 12:07
-
-
Save waiholiu/04ec1a85f4ca0653679f8aa537f1d90a to your computer and use it in GitHub Desktop.
This file contains 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
// part 1 - get this query from advanced find | |
var xml = `<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> | |
<entity name="new_widget"> | |
<attribute name="new_widgetid" /> | |
<attribute name="createdon" /> | |
<attribute name="new_isblue" /> | |
<order attribute="createdon" descending="false" /> | |
</entity> | |
</fetch>`; | |
// part 2 - enter in parameters | |
const query = "?fetchXml=" + xml; | |
const table = "new_widget"; | |
const primaryKey = "new_widgetid"; | |
const changeColumn = "new_isblue"; | |
const changeValue = true; | |
// execute this query to retrieve the view | |
Xrm.WebApi.retrieveMultipleRecords(table, query) | |
.then(result => { | |
for (var i = 0; i < result.entities.length; i++) { | |
// update each record | |
result.entities[i][changeColumn] = changeValue; | |
// this is needed because there is a limit of 52 records at once, so you need to space out the queries | |
setTimeout(function (currWidget) { | |
Xrm.WebApi.updateRecord(table, currWidget[primaryKey], currWidget).then(uresult => { console.log(uresult) }, | |
(error) => { console.log(error) }); | |
}, 1000 * i, result.entities[i]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment