Friday, 13 April 2012

Getting use of PublishXmlRequest SDK message to publish an Entity or a Web Resource

In Microsoft Dynamic CRM, when we perform any customization changes it is required to publish those changes. Below is the code which we can use to publish an Entity or a WebResource using “PublishXmlRequest” SDK message.

This code helps you to publish entity customization changes. Replace your entity’s logical name with below highlighted “entityName” variable.
#region Publish FormXMl
//Publish entity for which formxml has been changed 
PublishXmlRequest publishRequest = new PublishXmlRequest();
publishRequest.ParameterXml ="<importexportxml>" +
"    <entities>" +
"        <entity>" + entityName + "</entity>" +
"    </entities>" +
"    <nodes/>" +
"    <securityroles/>  " +
"    <settings/>" +
"    <workflows/>" +
"</importexportxml>";
try
{
organizationService.Execute(publishRequest);
}
catch (Exception)
{
throw new InvalidPluginExecutionException("Failure: FormXml                                                 publishing...");
}
#endregion

Similarly, we can publish a web resource using below code. Here you have to use a GUID of web resource record. Replace your web resource GUID with below highlighted value.

#region Publish Web Resource
 
PublishXmlRequest publishRequest = new PublishXmlRequest ();
 
publishRequest.ParameterXml =
"<importexportxml>" +
"   <webresources>"+
"       <webresource>{" + webResource.Id +"}</webresource>"+
"   </webresources>" +
"</importexportxml>";
try
{
organizationService.Execute(publishRequest);
}
catch (Exception)
{
throw new InvalidPluginExecutionException("Failure: WebResource publishing...");
}
#endregion

Below link will help you to identify what all other solution components can be published with PublishXmlRequest.

http://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.publishxmlrequest.parameterxml.aspx

No comments:

Post a Comment