web
You’re offline. This is a read only version of the page.
close
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

(2) ShareShare
ReportReport
Posted on by 45

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

I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at

    Hi Buddhi,

    Make sure that your environment is online because xrm.webapi.online only supports online mode.

    Try to execute the action with native web api:

    var req = new XMLHttpRequest();
    // change v9.0 to your version
    req.open("POST", Xrm.Page.context.getClientUrl()   "/api/data/v9.0/quotes(quoteid)/Microsoft.Dynamics.CRM.msdyn_CloseQuoteAsWon", 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 === 200) {
                Xrm.Utility.alertDialog(JSON.parse(this.response));
            } else {
                Xrm.Utility.alertDialog(this.response);
            }
        }
    };
    req.send();

    Regards,

    Clofly

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Try to use following code:

    var QuoteID = Xrm.Page.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: quoteclode,
        Status: 1,
    
        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) {
                //Success - No Return Data - Do Something
            }
        },
        function(error) {
            Xrm.Utility.alertDialog(error.message);
        }
    );

  • Buddhi Thathsala Perera Profile Picture
    45 on at

    Hi Andrew,

    I tried this code and actually I am getting this following error, (I am calling this function from a rbbon button)

    "State code is invalid or state code is valid but status code is invalid for a specified state code."

    By any chance do you have a solution for this? This  is actually going to the function (error)

    Thank you

  • Buddhi Thathsala Perera Profile Picture
    45 on at

    Hi Clofly,

    Thank you for the reply.  I tried this way as well and I am using online v9.1. I updated that and when i added my quoteid also, I get the following error

    "{"error":{"code":"0x8006088a","message":"Bad Request - Error in query syntax.","innererror":{"message":"Bad Request - Error in query syntax.","type":"Microsoft.OData.ODataException","stacktrace":" at Microsoft.OData.UriParser.SegmentKeyHandler.TryCreateKeySegmentFromParentheses(ODataPathSegment previous, KeySegment previousKeySegment, String parenthesisExpression, ODataUriResolver resolver, ODataPathSegment& keySegment, Boolean enableUriTemplateParsing)\r\n at Microsoft.OData.UriParser.ODataPathParser.TryBindKeyFromParentheses(String parenthesesSection)\r\n at Microsoft.OData.UriParser.ODataPathParser.TryCreateSegmentForNavigationSource(String identifier, String parenthesisExpression)\r\n at Microsoft.OData.UriParser.ODataPathParser.CreateFirstSegment(String segmentText)\r\n at Microsoft.OData.UriParser.ODataPathParser.ParsePath(ICollection`1 segments)\r\n at Microsoft.OData.UriParser.ODataPathFactory.BindPath(ICollection`1 segments, ODataUriParserConfiguration configuration)\r\n at Microsoft.OData.UriParser.ODataUriParser.Initialize()\r\n at System.Web.OData.Routing.DefaultODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer, Boolean template)\r\n at System.Web.OData.Routing.DefaultODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer)\r\n at Microsoft.Crm.Extensibility.ODataV4.Routing.CrmODataPathHandler.Parse(String serviceRoot, String odataPath, IServiceProvider requestContainer)"}}}"

    Can you please help me to resolve this?

    Thank you

  • cloflyMao Profile Picture
    25,210 on at

    Hi Buddhi,

    Could you share full code that is based on native web api request?

    Regards,

    Clofly

  • Buddhi Thathsala Perera Profile Picture
    45 on at

    Hi Clofly,

    Please find the code below,

    function wonQuote() {

       var QuoteID = Xrm.Page.data.entity.getId().replace("{", "").replace("}", "");

       var req = new XMLHttpRequest();

       req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/quotes(QuoteID)/Microsoft.Dynamics.CRM.msdyn_CloseQuoteAsWon", 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 === 200) {

                   Xrm.Utility.alertDialog(JSON.parse(this.response));

               } else {

                   Xrm.Utility.alertDialog(this.response);

               }

           }

       };

       req.send();

    }

    Thank you

  • cloflyMao Profile Picture
    25,210 on at

    Hi Buddhi,

    Form 3rd line of your code,

    req.open("POST", Xrm.Page.context.getClientUrl()   "/api/data/v9.1/quotes(QuoteID)/Microsoft.Dynamics.CRM.msdyn_CloseQuoteAsWon", true);

    Quotation marks is needed to QuoteID variable.

    Please change it to

    req.open("POST", Xrm.Page.context.getClientUrl()   "/api/data/v9.1/quotes("   QuoteID   ")/Microsoft.Dynamics.CRM.msdyn_CloseQuoteAsWon", true);
    

    Then you shall see a dialog with "object Object", then refresh record and it'll be closed.

    Regards,

    Clofly

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Buddhi,

    There is a chance that StatusCode is not valid one for the "Won" statuscode. Try to use -1 instead - change line

       Status: 1,

    to line

       Status: -1,

  • Buddhi Thathsala Perera Profile Picture
    45 on at

    Work this way perfectly. Thank you

  • cloflyMao Profile Picture
    25,210 on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 144 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 59

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans