Hi,
I am working with Dynamics 365 instance. If I am not wrong 'SetStateRequest' will be deprecated and 'UpdateRequest' should be used instead. I am trying to reactivate a Paid (Completed) invoice.
But with following 'UpdateRequest' it throws an error "The entity cannot be updated because it is read-only".
var invoiceToUpdate = new Entity("invoice", new Guid("D9588C16-EA18-E611-80E4-000D3A2362ED")); invoiceToUpdate["statecode"] = new OptionSetValue(0); invoiceToUpdate["statuscode"] = new OptionSetValue(1); UpdateRequest request = new UpdateRequest() { Target = invoiceToUpdate }; orgService.Execute(request);
But it works if I try 'SetStateRequest' as below:
SetStateRequest setStateRequest = new SetStateRequest() { EntityMoniker = new EntityReference { Id = new Guid("D9588C16-EA18-E611-80E4-000D3A2362ED"), LogicalName = "invoice", }, State = new OptionSetValue(0), Status = new OptionSetValue(1) }; orgService.Execute(setStateRequest);
Can anyone please explain why it works with a deprecated message but not with Suggested Method.
Thanks
*This post is locked for comments
Probably I am too late, but it could help someone in the future. I had exact same issue. But later I found out that my Invoice was missing Payment Date value. In worst case scenario you can update this field with using sql update (if on-premise, I know we should not do this), then SetStateRequest will work, either from console app or you can create ondemand workflow and use Change State step.
Hi @Scott
But strangely I can still change status from Paid(Complete) to Active(New) using a workflow but not through SDK!
Hi @Scott
But strangely I can still change status from Paid(Complete) to Active(New) using a workflow but not through SDK!
Hi,
Some system entities art imutable and cannot be updated when closed - even by the sdk. The ones I know about are quote, contract & invoice.
Hi,
a bug? Possibly..
This seems to work for some other entities:
community.dynamics.com/.../programmatically-activate-and-deactivate-sla-records-in-dynamics-crm
You might also try to call
service.Update(invoiceToUpdate);
May have to assign the id first: invoiceToUpdate.Id = ..
instead of execute(UpdateRequest), though it's not necessarily going to change anything
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156