Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waiholiu/04ec1a85f4ca0653679f8aa537f1d90a to your computer and use it in GitHub Desktop.
Save waiholiu/04ec1a85f4ca0653679f8aa537f1d90a to your computer and use it in GitHub Desktop.
// 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