问题描述:

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:

  • Using the Microsoft.Crm.Sdk.Messages.SetStateRequest(), setting only the Status property:

 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"

  • Using the Microsoft.Crm.Sdk.Messages.SetStateRequest(), setting both Status and the State property (setting the new State to the same current value):

 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."

  • Calling the Update method (passing in a quote instance) in the Microsoft.Xrm.Sdk.Client.OrganizationServiceContext class. I don't have the exact code I used when I tried this, but the error I was getting was:

    "The object cannot be updated because it is read-only."

    I made sure the connection was made using admin user credentials, but it didn't make a difference. I also found a few other posts like this one: read-only entity error but that didn't help either.

Question

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

网友答案:

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

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.

网友答案:

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.

相关阅读:
Top