Skip to content

Instantly share code, notes, and snippets.

@synesthesia
Last active February 3, 2017 09:59
Show Gist options
  • Save synesthesia/8b868a35331e10fccc3d5b88b021bf58 to your computer and use it in GitHub Desktop.
Save synesthesia/8b868a35331e10fccc3d5b88b021bf58 to your computer and use it in GitHub Desktop.
CRM entity status weirdness - the old way
// issue invoice
var setStateRequest = new SetStateRequest
{
EntityMoniker = new EntityReference(Invoice.EntityLogicalName, invoice.Id),
State = new OptionSetValue((int)InvoiceState.Active),
Status = new OptionSetValue((int)invoice_statuscode.ReadyToIssue)
};
Service.Execute(setStateRequest);
setStateToIssued: function (invoiceId) {
// workaround curly brace issue in Soap lib https://code.msdn.microsoft.com/SdkSoapjs-9b51b99a/view/Discussions
invoiceId = invoiceId.replace(/[{}]/g, "");
var moniker = new Sdk.EntityReference("invoice", invoiceId);
var state = 0; //active
var status = 293750003; // Ready To Issue
var req = new Sdk.SetStateRequest(moniker, state, status);
Sdk.Q.execute(req)
.then(function () {
Xrm.Page.data.entity.save("saveandclose");
}, function (error) {
common.log(error);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment