noobie
noobie

Reputation: 2607

Dynamics Crm 365 webapi - publish webresource via javascript

This article shows how to publish a webresource using javascript and soap.

http://mileyja.blogspot.com.au/2011/05/how-to-publish-all-customizations-using.html

is there a way to call a publish request in javascript via the web api instead?

Upvotes: 2

Views: 2046

Answers (1)

Federico Jousset
Federico Jousset

Reputation: 1761

Yes, it's perfectly possible using the PublishAllXml or PublishXml actions. You can use CRMRESTBuilder to easily test these actions:

PublishAllXml Example

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/PublishAllXml", 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
            alert("it worked!");
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();

PublishXml Example (it will publish only the account entity):

var parameters = {};
parameters.ParameterXml = "<importexportxml><entities><entity>account</entity></entities></importexportxml>";

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/PublishXml", 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
            alert("it worked!");
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send(JSON.stringify(parameters));

Upvotes: 6

Related Questions