Showing posts with label D365 Activated Quote. Show all posts
Showing posts with label D365 Activated Quote. Show all posts

Wednesday, August 14, 2019

Update the content of Activated Quote in CRM


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"newGuid(""));
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"newGuid(""));
activateQuote.State = new OptionSetValue(1); // Active
activateQuote.Status = new OptionSetValue(2); // InProgress
objService.Execute(activateQuote);

Hope this helps.