Development, Howto

How to close Quote as Won using WebApi

Following code can be used to close Quote as Won using JavaScript and WebApi:

var quoteclose = {
    "quoteid@odata.bind": "/quotes(D6ED8C34-EA0F-E711-810E-1458D041F8E8)",//replace with id of active quote
    "subject": "Quote Won Subject",
    "actualend": new Date(),
    "description": "Your description here"
};

var parameters = {
    "QuoteClose": quoteclose,
    "Status": -1
};

var context;

if (typeof GetGlobalContext === "function") {
    context = GetGlobalContext();
} else {
    context = Xrm.Page.context;
}

var req = new XMLHttpRequest();
req.open("POST", context.getClientUrl() + "/api/data/v8.2/WinQuote", 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 {
            var errorText = this.responseText;
            //Error and errorText variable contains an error - do something with it
        }
    }
};
req.send(JSON.stringify(parameters));

 

3 Comments

  1. Excellent post.
    To Close Quote as Lost, change “/api/data/v8.2/WinQuote” to “/api/data/v8.2/CloseQuote”.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.