Check other records associate with current record using Dynamic CRM 2011 workflow

Zhen Yuwang, 19 June 2012

Today I have a task to create a workflow which starts when a record is created. Then it waits for a while and check if there are any other records associated with this record. For example, when an Account is created, after a period of time, we want to know, is there any Contacts associated with this Account.

It doesn’t sound difficult. We can find those Contacts by Advanced Find like this:

 Check other records associate with current record using Dynamic CRM 2011 workflow

However, in workflow’s If condition, there is no Contact in related entities:

  Check other records associate with current record using Dynamic CRM 2011 workflow

Because it is One-To-Many relationship between Parent Customers (Account) and Contact, we need to figure out another way to check associated Contacts exist for this Account in workflow. 

First of all, let’s create a two option field called “Is Linked by Contact”. It is better if we hide that field on form, but just show here for testing.

 Check other records associate with current record using Dynamic CRM 2011 workflow

Then register a plugin in create/update/delete of Contact.

• In create stage, check parent customer’s value. If contains data, update that Account’s field to “Yes”.

• In update stage, check parent customer is changed or not. If it is changed, find out how many Contacts are associated with these 1 or 2 Accounts. Update their fields to “Yes” if results number is bigger than 0 and “No” if number is equal to 0.

• In delete stage, check parent customer’s value. If contains data, find out how many Contacts are associated with it. Update its fields by result number.

Now we can use that Boolean field in workflow like this:

 Check other records associate with current record using Dynamic CRM 2011 workflow

At the end, let’s test that workflow.

• Create an Account and link a Contact in 5 minutes.

 Check other records associate with current record using Dynamic CRM 2011 workflow

 Check other records associate with current record using Dynamic CRM 2011 workflow

 Check other records associate with current record using Dynamic CRM 2011 workflow

• Create an Account and link nothing in 5 minutes.

Check other records associate with current record using Dynamic CRM 2011 workflow

Check other records associate with current record using Dynamic CRM 2011 workflow

Check other records associate with current record using Dynamic CRM 2011 workflow