Tuesday 17 January 2012

Crm 4 workflow update children records from a parent record

Reference: http://www.dynamicscrmtrickbag.com/2009/09/02/account-contact-update/

Synchronize Child and Parent Records – with Workflows
Sherry Hale, a long-time Trick Bag reader, recently emailed me the following question:

…can you make a workflow that when an account address is updated, the contacts that share that address are also updated? It seems simple, but I can’t seem to pull in contact entity information on an account related workflow, nor can I start a contact child workflow from an account workflow.

Unfortunately, I had to answer her that she was correct: it’s not as simple as it seems it would be! An automatic workflow written against the Account entity doesn’t know anything about child records (like contacts, as in this example). In this sense, workflows are similar to Dynamics CRM Advanced Find: child records know lots about parent records, but parents don’t know anything about children.

You certainly can do that with code, and as soon as I find a good example of that kind of code out there I’ll post an update with a link to it. [If you know of any good examples of that or have written code to that effect yourself, please let me know and I'll give you ample credit!]

Updating Child Records from a Parent … with an On Demand Workflow
But, notice I said above that you can’t do it with an automatic workflow on the parent entity (in this case, account, but this is a more general point and will work the same way for anywhere in CRM where you’ve got a 1:N relationship). If you can live with an “on demand” workflow written for the child entity, it’s actually quite straightforward.

Here’s how you do it:

Create a new workflow for Contact, call it something descriptive like “Update Contact from Parent Account”.
Uncheck the default “Record is created” checkbox in the “Options for Automatic…” section, and make it available to run on demand:


Pull down the Add Step menu and give it a single Update Record action, on Contact, as I show in the above figure, then click Set Properties, and use Dynamic Values in the Form Assistant to update the fields on the child record(remember, the workflow will be run against any selected contacts, in this example!) with any values you want from the parent record (you can see the “Parent Customer (Account)” entity selected in the “Related Entities” list below, and also reflected in the values I’m using to update the fields on the contact record:


Save and Close, publish, and you’re ready to go.

If the workflow is published as an On Demand workflow for Contact, you’ll see it on any contact grid, including the so-called “Contact Associated View” for accounts. In an example like the following figure shows, I’ve clicked the Run Workflow button on the toolbar (which you won’t see unless you’ve got one of the on demand workflows published for Contact), and I’m about ready to change 119 contact records with updated address information from their parent account record.

So, Sherry, it might not be automatic…but it’s a lot better than doing them one at a time.

One More Thing…
You might be thinking: big deal: I can do that with a bulk edit. (select all the contact records you want and select Edit from the More Actions menu, and any updates you make to the fields there will be applied to all selected records). While it’s true that sometimes this will work, there are two limitations (at least) to the bulk edit approach that will still work in the workflow approach:

Plenty of fields can’t be edited with a bulk edit (e.g., certain lookup fields, such as Parent Customer). Any field can be updated with the workflow approach I showed here.
Another advantage of the workflow update approach is that you can apply logic in a workflow. For example, suppose you only want to update certain of those child records with the parent record values, and other ones you didn’t. If there are criteria determining which ones get the update and which ones don’t, you can put that into a “Check Condition” in a workflow, whereas “bulk edit” really is a bulk edit, and gets applied to every record no matter what.
I wrote a book on Dynamics CRM workflows, by the way, and it contains tons of examples like this one and other useful workflows. You can purchase the book on Lulu.com or on Amazon, and if you do, you can also get a (free) subscription to the online version of the book, where you can download the workflows themselves, customizations, and related content.

Here’s a link you can visit to find out more about my book and purchase it:

2 comments:

  1. http://crm2011distributewf.codeplex.com/

    The above will allow WF to work on child records. /e

    ReplyDelete