In my previous blog post about creating a “Clone” button, I showed you how to use JavaScript to open a new entity form, and then use “extraqs” to pass the values of the fields on the current form to the new form. However I did mentioned that if the fields you are going to copy contain “Multiple Lines of Text”, then this is not a good approach, as the URL has a length limit around 2000 characters. I will show you how to fix it today.
One way to fix it, is to use one of the OOTB (Out of the box) Dynamics CRM 2011 features called Entity Mapping. Before we do that, you need to make sure you have required the correct User Role to customize the system.
To make the demonstration easier, we will use the following example:
Say you open an Account record, then click Contacts on the left hand menu, then click the Contacts subgrid on the right, you will see the “Add New Contact” button on the ribbon area.
If you click the “Add New Contact” button, Dynamics CRM 2011 will open a new Contact entity form belonging to the current account.
We can see some of the fields have already been copied from the Account entity form, like “Business Phone” etc… Now we will use Entity Mapping to add “E-mail” into this list.
First go to Solutions -> Default Solution, and extend the Entity you want the value to be copied from, in this example it is the Account entity, and click “1:N Relationships”.
Then click “New 1-to-Many Relationship” to create a new relationship from Account to Contact:
After you save the Relationship, you can click Mappings on the left, then click New to create the mapping we want:
You can select the original field and the target field, we select from Email to Email here:
Now if you repeat the step we did above, creating a Contact within an Account record, you will see the Email field has been copied to the new Contact form.
We can see, using this approach is tidier, as we don’t need to create our own JavaScript file and it is a supported option. Hope you can use it in your next project and feel free to let me know if you find it useful or got any feedback.