How to publish enity form in javascript

What for?

Some time ago I had to create and customize ~20 entities. After editing form, saving, publishing and reloading over and over again I thought about creating custom button for publishing. Yeah – why not.

But this functionality already exists

Yes, that’s true. If anyone hasn’t check how does the built-in publish button works here’s the hint: SaveAndPublish(). Problem is that this method does not have success callback function.

So, what’s next

First of all – SOAPLogger :). In a few minutes you can get soap request which can be used in JavaScript (after slight modifications).

	GetPublishRequest: function(entityName){
        var request = "";
        request += '<request i:type="b:PublishXmlRequest" xmlns:a="" xmlns:b="">';
        request += '	<a:Parameters xmlns:c="">';
        request += '		<a:KeyValuePairOfstringanyType>';
        request += '        	<c:key>ParameterXml</c:key>';
        request += '            <c:value i:type="d:string\" xmlns:d="">';
		request += '				&lt;importexportxml&gt;&lt;entities&gt;&lt;entity&gt;' + entityName + '&lt;/entity&gt;&lt;/entities&gt;&lt;/importexportxml&gt;';
        request += '            </c:value>';
        request += '          </a:KeyValuePairOfstringanyType>';
        request += '        </a:Parameters>';
        request += '    <a:RequestId i:nil="true" />';
        request += '	<a:RequestName>PublishXml</a:RequestName>';
        request += '</request>';

        return request;

When request is ready, it needs to be invoked – I do prefer reusable code, so I’m using XrmServiceToolkit library.

XrmServiceToolkit.Soap.Execute(BDS.Products.SaveAndPublish.GetPublishRequest(entityLogicalName), anyCallbackHere);

This solution does not use built-in “Publishing customizations…” pop-up, this can be implemented in any way.

Have an own opinion?