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="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">'; request += ' <a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">'; request += ' <a:KeyValuePairOfstringanyType>'; request += ' <c:key>ParameterXml</c:key>'; request += ' <c:value i:type="d:string\" xmlns:d="http://www.w3.org/2001/XMLSchema">'; request += ' <importexportxml><entities><entity>' + entityName + '</entity></entities></importexportxml>'; 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.