Last active
February 3, 2017 10:42
-
-
Save synesthesia/9b3ea63cc4fbdcd911725459e0d2e07c to your computer and use it in GitHub Desktop.
Original attempt to change invoice status from Javascript using the REST API
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
var setStateToIssued = function(invoiceId) { | |
window.console.log('setStateToIssued(' + invoiceId + ')'); | |
invoiceId = invoiceId.replace(/[{}]/g, ""); | |
var url = Xrm.Page.context.getClientUrl() + "/api/data/v8.2/invoices(" + invoiceId + ")"; | |
var entity = {}; | |
//entity.statecode = 0; //commenting because we think setting state AND status causes workflows to fire twice | |
entity.statuscode = 293750003; // Ready To Issue | |
var req = new XMLHttpRequest(); | |
req.open("PATCH", url, true); | |
req.setRequestHeader("OData-Version", "4.0"); | |
req.setRequestHeader("Accept", "application/json"); | |
req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); | |
req.onreadystatechange = function () { | |
if (this.readyState === 4) { | |
req.onreadystatechange = null; | |
if (this.status === 204) { | |
//Success - No Return Data | |
Xrm.Page.ui.close(); | |
} else { | |
Xrm.Utility.alertDialog(this.statusText); | |
} | |
}}; | |
req.send(JSON.stringify(entity)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment