Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Quote Revise Button Does not Set Correct Status

(0) ShareShare
ReportReport
Posted on by 535

Hi,

In Dynamics 365 release wave 2 version and previous versions, the default "Revise" button on "Quote" form sets "statuscode" to the "default statuscode(Lost)" value.

I am using that "default statuscode(Lost)" value for the "Close Quote" button.

There is also "Revise" statuscode value that i want to use for the Revise button. Since "Revise" button doesn't allow you to choose your statuscode, all of the revised Quotes' statuscode become "Lost" which is wrong.

How can i change Revise button statuscode value? Whether via UI or via code?

  • Suggested answer
    furkank Profile Picture
    furkank 535 on at
    RE: Quote Revise Button Does not Set Correct Status

    Here is the solution I found by myself;

    public class SetQuoteReviseStatusPreCreate : Plugin
        {
            public SetQuoteReviseStatusPreCreate() : base(typeof(SetQuoteReviseStatusPreCreate))
            {
                RegisteredEvents.Add(new PluginConfiguration((int)PluginExecutionStage.PreOperation, "Create", "quote", ExecutePlugin));
            }
    
            private static void ExecutePlugin(LocalPluginContext localContext)
            {
                if (localContext == null)
                {
                    throw new ArgumentNullException("localContext");
                }
    
                var context = localContext.PluginExecutionContext;
                var service = localContext.OrganizationService;
                var tracingService = localContext.TracingService;
                var orgContext = new OrganizationServiceContext(service);
    
                if (!context.InputParameters.ContainsKey("Target") || !(context.InputParameters["Target"] is Entity))
                {
                    return;
                }
    
                var target = (Entity)context.InputParameters["Target"];
    
                if (!target.Attributes.Contains("revisionnumber") || target.GetAttributeValue("revisionnumber") < 1)
                {
                    tracingService.Trace("This Quote isn't a Revised Quote.");
                    return;
                }
    
                while (context != null)
                {
                    if (context.MessageName != "Revise")
                    {
                        context = context.ParentContext;
                        continue;
                    }
                    else
                        break;
                }
    
                if (context == null)
                {
                    tracingService.Trace("ParentContext is empty or does not have Revise MessageName.");
                    return;
                }
    
                if (!context.InputParameters.Contains("QuoteId"))
                {
                    tracingService.Trace("ParentContext does not contain QuoteId.");
                    return;
                }
    
                var parentContextId = (Guid)context.InputParameters["QuoteId"];
    
                tracingService.Trace($"Parent Quote ID: {parentContextId}");
    
                var revisedQuote = service.Retrieve("quote", parentContextId, new ColumnSet(new string[] { "statuscode" }));
                if (revisedQuote.GetAttributeValue("statuscode").Value == 899270011)
                    return; //Already revised, no need to update
    
                tracingService.Trace("Starting Updating Revised Quote Statuscode to Revised");
    
                var updateRevisedQuote = new Entity("quote", parentContextId);
                updateRevisedQuote["statuscode"] = new OptionSetValue(899270011);
                service.Update(updateRevisedQuote);
    
                tracingService.Trace("Revised Quote Statuscode Updated");
            }
        }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans