Friday, October 17, 2008

MS CRM Address Sync Workflow

In Microsoft CRM, you can have many contacts connected to a single account. When you initially create the contact, it takes the address from the account record, but the user has the option to change the address. This is a nice feature because it supports companies that have employees who are not all located in the same building. But what happens when you change the account address? All those contacts end up staying at the old address. You could manually change them, but there is no need because you can automate this process. The Microsoft CRM Team blog has some suggestions to remedy this problem, but it requires building a custom program (which they provide) and installing it on the CRM server. This could be problematic for users of CRM On-line, so I have a solution using the workflow tool.

In the Contact entity, create a couple new attributes: one will be called “Sync with Account Address” as a bit field (yes/no), and the other is wfDateOfAddressSync (Date & Time). Allow me to digress on the name of the second attribute. I use the “wf” in front of attributes that will not be visible on a form, but are used by workflow to control actions. This makes it easy for me to distinguish them from user attributes, and serves as a reminder so that in the future I don’t delete it because it appears to be unused. Place the new bit attribute on the form in a conspicuous location in the address section and publish the changes.

In the Account entity, create a new field attribute wfDateOfAddressChange (Date & Time) and publish the changes.

Now create a workflow called Trigger Address Sync for the Account entity. This workflow should execute when a new Account is created, or when one of the address fields changes. It will update the account record and place the Workflow Execution time in the wfDateOfAddressChange attribute. Make sure the workflow Scope is set to Organization and Publish it.

Next, create a workflow for the Contact entity. Set this one up to “Start When” the a Contact is created, or if either the “Sync with Account Address” attribute or wfDateOfAddressSync attribute changes. Now add a condition to only execute the rest of the workflow if the Sync with Account Address attribute is Yes, then add a timeout condition that will wait for the wfDateOfAddressSync on the Account entity to not be equal to the Contact entities wfDateOfAddressChange attribute. The final step is to update the contacts’ address fields to be the same as the Parent (Account) address fields, and update the wfDateOfAddressSync attribute to take on the value of the Parent (Account) wfDateOfAddressChange attribute. This last item will create a loop by triggering this workflow to start again (by changing the date attribute) and wait for the next Account address change. Make sure the workflow Scope is set to Organization and Publish it.

Remember, this new Contact workflow will not start synchronizing until they have either been manually applied to existing contacts, or someone updates one of the Start When fields (mentioned above) fields.

Now go test it and have fun!

No comments: