Views:

Overview

In this scenario our business requirement is that when an Account's address is updated you need to update all the related Contact addresses with the same data. However, we also have a validation rule on updating contact records that may throw an error. To circumvent this, we use the SmartFlowExceptionGuard function.

North52 Decision Suite

The North52 Decision Suite solution works like this:

  • We create a formula that triggers whenever any of the address 1 fields change on an Account entity
  • The formula finds all the Contacts associated to the Account 
  • It will then loop over all the Contacts and update their address information with that of Account entity
    • If for some reason an error occurs while updating these addresses, we will instead update the description field of the Contact to inform the User the address sync failed for that particular record

Formula - Address Sync with SmartFlowExceptionGuard

  •  Create a new formula, setting the following values in the Formula Guide:
    • Set the Editor to Classic
    • Set the Formula Type to Save - Perform Action
    • Set Source Entity to Account
    • Click Create
  • Change the Name of the Classic Formula to  Sync. Account Address with all Contacts and protect against Exceptions
  • Set Event to Update
  • Expand Source & Target
  • Set Source Entity Property (hold down control key to multi-select) to Address 1: City, Address 1: State/Province, Address 1: Street 1, Address 1: Street 2, Address 1: Street 3,Address 1: ZIP/Postal Code 
  • Copy the following formula into the editor:
    ForEachRecord(
    
      FindRecords('contact', 'parentcustomerid', [account.accountid], 'contactid'), 
    
      SmartFlowExceptionGuard(
        UpdateRecord('contact',
          CurrentRecord('contactid'),
          SetAttribute('address1_line1', [account.address1_line1]),
          SetAttribute('address1_line2', [account.address1_line2]),
          SetAttribute('address1_line3', [account.address1_line3]),
          SetAttribute('address1_city', [account.address1_city]),
          SetAttribute('address1_postalcode', [account.address1_postalcode]),
          SetAttribute('address1_country', [account.address1_country]),
          SetAttribute('description', '')
        ), 
    
        UpdateRecord('contact',
          CurrentRecord('contactid'),
          SetAttribute('description', 'Address not synced with Parent Account because: ' + GetVar('smartflowexceptionguardmessage') ) 
        )
    
    ))
  • Click Save

Formula - Contact Validation

We will setup a validation formula that throws an error whenever a Contacts email address doesn't contain a certain value.

Note: It might be wise to deactivate this validation formula when not testing the Address Sync formula as it may interfere with other processes.  

  •  Create a new formula, setting the following values in the Formula Guide:
    • Set the Editor to Classic
    • Set the Formula Type to Validation
    • Set Source Entity to Contact
    • Click Create
  • Change the Name of the Classic Formula to  Contact - Batman Validation
  • Expand Source & Target
  • Set Source Entity Property (hold down control key to multi-select) to Address 1: City, Address 1: State/Province, Address 1: Street 1, Address 1: Street 2, Address 1: Street 3,Address 1: ZIP/Postal Code 
  • Copy the following formula into the editor:
    if(
      Contains([contact.emailaddress1], 'batman'),
        'NoOp',
        'Do not sync')
  • Click Save
  • You are ready to test

Testing

To test the scenario above, simply make a change to one of the address fields in an Account that has child Contacts.

  • You will see that the addresses synchronize unless their email do not contain 'batman'.
  • If that is the case, the description field of the Contact will instead be updated with the string Address not synced with Parent Account


 

Did you know?

North52 has a powerful distributed cache for advanced decision logic

xCache allows you to configure and scale your Dynamics 365/CRM applications running On-Premise or Online. It allows dynamic system configuration and removes performance bottlenecks related to data storage. xCache provides Dynamics 365/CRM with an extremely fast and scalable distributed cache to power your advanced decision logic.

xCache in Dynamics CRM  lets you cache static application data, and also load dynamic cache items for applications running in a single or multi-server configuration.

Learn more and see examples of xCache