Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

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

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: The entity cannot be updated because it is read-only Error with UpdateRequest but works with deprecated message

    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.

  • shaan Profile Picture
    shaan 272 on at
    RE: The entity cannot be updated because it is read-only Error with UpdateRequest but works with deprecated message

    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
    shaan 272 on at
    RE: The entity cannot be updated because it is read-only Error with UpdateRequest but works with deprecated message

    Hi @Scott 

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

  • Suggested answer
    ScottDurow Profile Picture
    ScottDurow 50,177 on at
    RE: The entity cannot be updated because it is read-only Error with UpdateRequest but works with deprecated message

    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.

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: The entity cannot be updated because it is read-only Error with UpdateRequest but works with deprecated message

    Hi Shaan,

    Refer the community thread below.

    community.dynamics.com/.../156272

    Hope this helps.

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: The entity cannot be updated because it is read-only Error with UpdateRequest but works with deprecated message

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans