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 :
Customer experience | Sales, Customer Insights,...
Unanswered

Change state and status by script

(0) ShareShare
ReportReport
Posted on by 55

Hello, I became aware of something in Dynamics programming through C#. It is about setting the state as well as status code through the script.

Although all permissions are given for both read and write, I get the exception/error : "This entity is readonly." The setting of the state and status code is done as follows:

entity["statecode"] = new OptionSetValue(0);
entity["statuscode"] = new OptionSetValue(1);
service.Update(entity);


The interesting thing is that this way works in many other examples... but not for the "invoice" entity. So what is being done? I tried this with the SetStateRequest class - which also eventually led to success.

SetStateRequest setStateRequest = new SetStateRequest()
{
    
    EntityMoniker = new EntityReference
    {
        Id = invoice.Id,
        LogicalName = "invoice",
    },
    State = new OptionSetValue(0),
    Status = new OptionSetValue(1)
};

service.Execute(setStateRequest);

Now my question about this - what is the crucial reason that the top lines of code point to "readonly" and the bottom one works. Is this possibly just a "bug" or is there something behind it?

Thank you and have a pleasant day.

I have the same question (0)

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans