rtorres
rtorres

Reputation: 2951

How to update only the StatusCode of an entity in MS CRM Dynamics 2013

I'm trying to update a Quote status code in MS CRM 2013 via the SDK. The issue is that I only need to update the status code and not the state code in the quote. The current State of the quote is Active and the current Status value is 10 (which I need to update to 11). I've tried a few things unsuccessfully so far:

    var request = new SetStateRequest
    {
        EntityMoniker = new EntityReference("quote", quoteId),
        Status = new OptionSetValue(11)
    };

    var resp = (SetStateResponse) orgService.Execute(request);

    // throws Exception Microsoft.Xrm.Sdk.OrganizationServiceFault:
    // "Required field 'State' is missing"
    var request = new SetStateRequest
    {
        EntityMoniker = new EntityReference("quote", quoteId),
        State = new OptionSetValue((int) QuoteState.Active),
        Status = new OptionSetValue(11)
    };

    var resp = (SetStateResponse) orgService.Execute(request);

    // throws Exception Microsoft.Xrm.Sdk.OrganizationServiceFault:
    // "The quote cannot be activated because it is not in draft state."

Question

Is there a way to programmatically update the Quote status code without altering the state code? If so, how?

Upvotes: 1

Views: 9504

Answers (2)

rtorres
rtorres

Reputation: 2951

Seems like my issue has to do with the current state of the quote - Active. Apparently, Active quotes cannot be updated for the most part - I wasn't able to update its status reason even through the GUI. I found this post with a similar scenario.

As the post suggests, I was able to programmatically update my quote status by first sending it back to Draft/In Progress, and then updating its state/status to Active/11.

Upvotes: 1

Guido Preite
Guido Preite

Reputation: 15128

The Status Reason (statuscode field) of a entity depends on the Status (statecode field) value.

For example the standard values for a Quote are the following

enter image description here

so inside your SetStateRequest you need to set the a valid combination (for example you can't set a quote to be Active and Revised) specifying both the values.

In your question you wrote that you are using custom Status Reason, you need to check under which Status you added them and try again.

Upvotes: 2

Related Questions