Pages

Thursday, February 28, 2013

CRM 2011 Copy Utility


This plugin allows you copy fields from a parent record to all child records in a 1:N relationship. For example, this plugin can be used to copy the address fields of an account to all the contacts of that parent account (a common scenario).

Out of the box you are able to map fields from a parent entity to a child entity when the child record gets created. However beyond this point in time if details are changed on the parent record they will no longer be copied to the child records. Similarly there is no out of the box capability to copy changes made to the parent record down to all child records.

This plugin allows this option to be configured. You are able to configure which 1:N relationship this plugin will work against as well as the fields that are to be mapped between the parent and child entities. The plugin does not validate attribute types so you will need to ensure in your configuration that the fields be mapped are of the same type.

The following is a walk through of how to configure this plugin:

  • Download the DLL from here
  • Use the Plugin Registration tool to connect to your environment and register the plugin
  • Register a New Step 
    • Message: Update
    • Primary Entity: Parent entity
    • Remaining settings: Optional


  • In the Unsecure Configuration update the XML to specify the fields to copy
    • <setting name="source"> : parent entity name e.g. account
    • <setting name="sourceid"> :  parent entity primary key e.g. accountid
    • <setting name="target">  : child entity name e.g. contact
    • <setting name="targetid"> : child entity foreign key e.g. parentcustomerid
    • <setting name="numberoffield"> : total number of fields being copied
    • <setting name="src_fieldn"> : name of source field to copy
    • <setting name="dest_fieldn"> : name of corresponding target field to be copied too
Note: There is no validation of any of these fields. You need to ensure that:

    • All the field names are correct
    • The corresponding "src" and "dest" fields have the same definition 

For example, the following XML can be used to copy the address fields from the parent account record to the child contact records: 
<Settings>
<setting name="source">  
<value>account</value>
</setting>
<setting name="sourceid">  
<value>accountid</value>
</setting>
<setting name="target">
 <value>contact</value>
</setting>
<setting name="targetid">
 <value>parentcustomerid</value>
</setting>
<setting name="numberoffield">
 <value>8</value>
</setting>
<setting name="src_field1">
 <value>Address1_line1</value>
</setting>
<setting name="src_field2">
 <value>Address1_line2</value>
</setting>
<setting name="src_field3">
 <value>Address1_line3</value>
</setting>
<setting name="src_field4">
 <value>Address1_city</value>
</setting>
<setting name="src_field5">
 <value>Address1_stateorprovince</value>
</setting>
<setting name="src_field6">
 <value>Address1_postalcode</value>
</setting>
<setting name="src_field7">
 <value>Address1_country</value>
</setting>
<setting name="src_field8">
 <value>Address1_telephone1</value>
</setting>
<setting name="dest_field1">
 <value>Address1_line1</value>
</setting>
<setting name="dest_field2">
 <value>Address1_line2</value>
</setting>
<setting name="dest_field3">
 <value>Address1_line3</value>
</setting>
<setting name="dest_field4">
 <value>Address1_city</value>
</setting>
<setting name="dest_field5">
 <value>Address1_stateorprovince</value>
</setting>
<setting name="dest_field6">
 <value>Address1_postalcode</value>
</setting>
<setting name="dest_field7">
 <value>Address1_country</value>
</setting>
<setting name="dest_field8">
 <value>Address1_telephone1</value>
</setting>
</Settings>


  • Register a New Image called "postEntityImage"


  • Test and ensure that it is working




1 comment:

  1. Good morning,
    I have tried to load your plug-in into CRM 2013 online.
    Unfortunately I get an error "Unable to load the specified Plugin Assembly".

    I would appreciate your advice.

    The detailed error detail is pasted below.

    Thanks
    Peter

    Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Users\peter_000\Downloads\CRM Copy Utility\Copy Utility Plugin\Utility Plugin.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
    at System.Reflection.Assembly.LoadFrom(String assemblyFile)
    at Microsoft.Crm.Tools.PluginRegistration.AssemblyReader.LoadAssembly(String path)
    at Microsoft.Crm.Tools.PluginRegistration.AssemblyReader.RetrievePluginsFromAssembly(String path)
    at Microsoft.Crm.Tools.PluginRegistration.AssemblyReader.RetrievePluginsFromAssembly(String path)
    at Microsoft.Crm.Tools.PluginRegistration.RegistrationHelper.RetrievePluginsFromAssembly(String pathToAssembly)
    at Microsoft.Crm.Tools.PluginRegistration.PluginRegistrationForm.btnLoadAssembly_Click(Object sender, EventArgs e)
    Inner Exception: System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

    ReplyDelete