web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

The entity cannot be updated because it is read-only Error with UpdateRequest but works with deprecated message

(0) ShareShare
ReportReport
Posted on by 272

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.

6825.Capture3.JPG 

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    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

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Shaan,

    Refer the community thread below.

    community.dynamics.com/.../156272

    Hope this helps.

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    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.

  • shaan Profile Picture
    272 on at

    Hi @Scott 

    But strangely I can still change status from Paid(Complete) to Active(New) using a workflow but not through SDK!

  • shaan Profile Picture
    272 on at

    Hi @Scott

    But strangely I can still change status from Paid(Complete) to Active(New) using a workflow but not through SDK!

  • Community Member Profile Picture
    on at

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans