Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Web API Action for Quote - WinQuote Action

(0) ShareShare
ReportReport
Posted on by 43

Hi Team,

Can anyone please help me with the following code to close the quote as Won using WinQuote action?

I want to call this function from the ribbon after activating the Quote. At the moment I am getting the error message. 

function wonQuote() {

var parameters = {};
var QuoteID = Xrm.Page.data.entity.getId();
var entity = {};
entity.id = "6a769b48-c34e-ea11-a812-000d3ad1c2b4";
entity.entityType = "quote";
//parameters.entity = entity;
parameters.Status = 1;

var getWinQuoteRequest = {
entity: parameters.entity,
Status: parameters.Status,

getMetadata: function () {
return {
boundParameter: "entity",
parameterTypes: {
"entity": {
"typeName": "mscrm.quote",
"structuralProperty": 5
},
"Status": {
"typeName": "Edm.Int32",
"structuralProperty": 2
}
},
operationType: 0,
operationName: "WinQuote"
};
}
};

Xrm.WebApi.online.execute(getWinQuoteRequest).then(
function success(result) {

if (result.ok) {
//Success - No Return Data - Do Something
}
},
function (error) {

Xrm.Utility.alertDialog(error.message);
}
);

}

Thank you heaps team

  • RoelG Profile Picture
    RoelG 1,090 on at
    RE: Web API Action for Quote - WinQuote Action

    For anyone still looking for the correct code:

        var QuoteID = formContext.data.entity.getId().replace("{", "").replace("}", "");
    
        var quoteclose = {
            "quoteid@odata.bind": "/quotes("   QuoteID   ")",
            "subject": "Quote Won Subject",
            "actualend": new Date(),
            "description": "Your description here"
        };
    
        var winQuoteRequest = {
            QuoteClose: quoteclose,
            Status: 4, // Won
    
            getMetadata: function () {
                return {
                    boundParameter: null,
                    parameterTypes: {
                        "QuoteClose": {
                            "typeName": "mscrm.quoteclose",
                            "structuralProperty": 5
                        },
                        "Status": {
                            "typeName": "Edm.Int32",
                            "structuralProperty": 1
                        }
                    },
                    operationType: 0,
                    operationName: "WinQuote"
                };
            }
        };
    
        Xrm.WebApi.online.execute(winQuoteRequest).then(
            function success(result) {
                if (result.ok) {
                    formContext.data.refresh(false);
                }
            },
            function (error) {
                Xrm.Utility.alertDialog(error.message);
            }
        );

  • RE: Web API Action for Quote - WinQuote Action

    That won't help then. I want to close the quote as won and update the date field. I will be closing the quote as won only after activating the quote.

    Kind regards

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Web API Action for Quote - WinQuote Action

    Hello,

    Closed On is a regular field on quote as far as I can see. To set it just call the update of quote using Xrm.WebApi.update method (not Xrm.WebApi.execute). One thing you should keep in mind - field is editable while quote is in "Draft" state so you will be able to update it only when quote is "Draft".

  • RE: Web API Action for Quote - WinQuote Action

    Hi Andrew,

    Yes it is in the quote entity. Out of thebox field as well.

    Thanks

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Web API Action for Quote - WinQuote Action

    Where is ClosedOn field located? Is it on quote entity?

  • RE: Web API Action for Quote - WinQuote Action

    Hi Andrew,

    Thank you for your reply.

    I tried the way you suggested but unable to make it work. Please point out if you could to make it work.

      var winQuoteRequest = {

           QuoteClose: quoteclose,

           Status: -1,

           Closedon: new Date(),

           getMetadata: function () {

               return {

                   boundParameter: null,

                   parameterTypes: {

                       "QuoteClose": {

                           "typeName": "mscrm.quoteclose",

                           "structuralProperty": 5

                       },

                       "Status": {

                           "typeName": "Edm.Int32",

                           "structuralProperty": 1

                       },

                        "Closedon": {

                            "typeName": "Edm.DateTimeOffset",

                           "structuralProperty": 1

                       }

                   },

                   operationType: 0,

                   operationName: "WinQuote"

               };

           }

       };

    much appreciated.

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Web API Action for Quote - WinQuote Action

    Try to use new Date() instead.

  • RE: Web API Action for Quote - WinQuote Action

    Hi Guys I am trying to update the closed on date using

    date = new date();

    Do you have any idea how I can acheive this whith this same code?

    Thank you

  • RE: Web API Action for Quote - WinQuote Action

    Hi Clofly no this didn't work sorry

  • cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Web API Action for Quote - WinQuote Action

    Hi Buddhi,

    Does my modified code also work for you?

    Regards,

    Clofly

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,494 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