How to Map Account Address into Contact
Most people understand how to map account address information to a contact using the Map features of CRM. It is very powerful and easy to configure and implement. But what happens when the contact switches companies? The user then has to manually update the contacts address to match the accounts! Not to mention any other fields which you have on the contact that are derived from the account. Out of the box that’s as many as 77 fields!
With CRM Rules, having the JavaScript do this automatically is a breeze.
Step 1: Get CRM Rules ready
Assuming you have installed the product, make sure you have create/updated the metadata for both contact and account. Go to Settings: Entities, open up Contact from the grid, and hit the Create/Update button.
Do the same for Account if you haven’t already.
Make sure everything finishes by looking in the Deployment History Grid
Step 2: Create your Rule
Even though this is a highly complex rule, it can all be created using our Simple Rule form.
Even though we are copying the account fields, it happens on the contact form.
Then we can find the pre-created condition of the Parent Customer Changed.
We come back and look like this:
We have to hit the New button after we hit the lookup button since this action can’t be one of the ones we create automatically.
The rule action is a copy field(s) from lookup entity action. Notice the fields that are added once we select that action type. Also notice the field on the right that says Generate Copy Records for All fields. A word of caution – the system matches by attribute name – and account and contact have a tremendous amount of fields with the same name! This may result in more fields than you actually want to map, so you will have to perform some cleanup after. The mapping occurs after you hit the Save button when a plugin we have runs. In my system, this automatic mapping resulted in 80 fields being mapped! That is a LOT OF FIELDS!! You might ask, what happens if the code maps a field that isn’t on my form? No worries, we make sure the field is on the form before we try to copy it, ensuring that we won’t cause any errors.
Deleting is a lot easier than creating, so I ended up deleting about 40 of them, and just mapped my address fields.
Hit save and Close and OK, and you will find yourself back on the simple form.
Mapping these fields every time you open the form may not make sense, so we will uncheck that box. Then hit validate – the rule should say Ready to Deploy after a moment.
Hit Deploy – and give it a minute….refresh the grid and it will save “Deployed”
Open a contact, change the parent account and watch it work!
The Gory Details…
In case you are interested in what you just did, CRM Rules doesn’t try to hide anything like the Business Rules that you can do with 2013. Open the same rule and switch the form to the Advanced Form. Then select the Generated Code tab. You will see 135 lines of highly complex code, inside of 4 methods, that you didn’t have to figure out how to write, nor pay someone to figure it out.
This is why we love CRM Rules!