Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

How can I update the opportunity stage when creating a new quote record?

Posted on by 35

I would like to update the opportunity pipeline stage when creating the first quote record. Is there a way to do this using javascript?

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: How can I update the opportunity stage when creating a new quote record?

    Hi,

    Glat that it worked. Please mark my answer verified if my asnwer were helpful.

    If found helpful, Please mark my answer verified.

  • Deivison Profile Picture
    Deivison 35 on at
    RE: How can I update the opportunity stage when creating a new quote record?

    Thank you so much, it worked!

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: How can I update the opportunity stage when creating a new quote record?

    Hi,

    Try below javascript code to set active stage pipeline.

    formContext.data.process.setActiveStage(stageId, callbackFunction);

    Parameter

    stageId String Yes The ID of the completed stage for the entity to make the active stage.

    callbackFunction Function No A function to call when the operation is complete. This callback function is passed one of the following string values to indicate whether the operation succeeded:

    - success: The operation succeeded.

    - invalid: The processId isn’t valid or the process isn’t enabled.

    You can also use web api to update bpf stage if form context is different.

    var entity = {};
    entity["activestageid@odata.bind"] = "/processstages(00000000-0000-0000-00000001)";
    entity["opportunityid@odata.bind"] = "/opportunities(00000000-0000-0000-00000001)";
    
    var req = new XMLHttpRequest();
    req.open("PATCH", Xrm.Page.context.getClientUrl()   "/api/data/v9.1/leadtoopportunitysalesprocesses(00000000-0000-0000-0000-000000000000)", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 204) {
                //Success - No Return Data - Do Something
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(entity));

    If found helpful, Please mark my answer verified.

  • Deivison Profile Picture
    Deivison 35 on at
    RE: How can I update the opportunity stage when creating a new quote record?

    Because I would like to update the step only after creating the first record and I'm not familiar with using workflow.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How can I update the opportunity stage when creating a new quote record?

    Hello,

    There is a way but why do you want to do it using JavaScript - more cleaner and no-code way - to use Workflow or Flow.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans