Thursday, 16 July 2015

Update the content of Activated Quote in CRM

Hi,
 
We got a situation as, the quote should activated for triggering a workflow and from workflow on based on some conditions we need to update the same quote. This is not possible as the quote becomes Read-Only immediately after you activate.
 
If we want to update it, the option is revising the quote which closes the current quote and creates a new quote where we don't want to create new quotes.
 
After some search, we found a way for doing it and the way is very simple. Just change the state of quote to Draft, update the data and then change the quote state to Active which will not create any new quote.
 
We can do this using a system workflow and also from SDK.
 
System Workflow
 
SDK
// Change the Quote to Draft State
SetStateRequest draftQuote = new SetStateRequest();
draftQuote.EntityMoniker = new EntityReference("quote", new Guid(""));
draftQuote.State = new OptionSetValue(0); // Draft
draftQuote.Status = new OptionSetValue(1); // InProgress
objService.Execute(draftQuote);

// Update the Quote
Entity entQuote = new Entity("quote");
entQuote.Attributes["name"] = "testing1";
entQuote.Id = new Guid("DA5768B5-D62A-E511-80E0-FC15B4283778");
objService.Update(entQuote);

// Change the Quote to Active State.
SetStateRequest activateQuote = new SetStateRequest();
activateQuote.EntityMoniker = new EntityReference("quote", new Guid(""));
activateQuote.State = new OptionSetValue(1); // Active
activateQuote.Status = new OptionSetValue(2); // InProgress
objService.Execute(activateQuote);

Hope this helps.

--
Happy CRM'ing
Gopinath 

3 comments:

  1. Is there any workaround for this issue that does not involve writing workflows or accessing the SDK. I am a customiser only, and have no access to SDK.

    Using CRM 2016, OOB functionality, no changes to Quotes entity, and once a quote is activated, I cannot creation a revision. Clearly this is meant to be possible because the screen shows Revision ID field.

    Error message returned:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The entity cannot be updated because it is read-only.Detail:

    -2147220946

    The entity cannot be updated because it is read-only.
    2016-04-07T04:53:34.3752969Z




    ReplyDelete
  2. Is there any workaround for this issue that does not involve writing workflows or accessing the SDK. I am a customiser only, and have no access to SDK.

    Using CRM 2016, OOB functionality, no changes to Quotes entity, and once a quote is activated, I cannot creation a revision. Clearly this is meant to be possible because the screen shows Revision ID field.

    Error message returned:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The entity cannot be updated because it is read-only.Detail:

    -2147220946

    The entity cannot be updated because it is read-only.
    2016-04-07T04:53:34.3752969Z




    ReplyDelete
  3. Sounds like you may already have a workflow, process, or script that is trying to update the Quote after it has been Activated; try creating a real-time workflow that runs BEFORE the status change to update the fields.

    ReplyDelete