Views:

Scenario Overview

In the previous sample we saw the following requirement that we had a 3rd party integration creating Account records within Dynamics CRM. This integration cannot set the ownerid field of the record but it can set a text field with the name of the owner. So we need to use this information to lookup the User ID value & set it to the owner of the Account record. 

In this advanced scenario we need to set a default if no User ID is found when we use the Owner Text to perform the lookup.

N52 Formula Manager Solution

The Formula Manager solution works like this,

  • A formula is set to execute for the create event of the Account entity
  • It checks that the OwnerText field has data before it executes the main formula
  • The formula lookups & set a variable called 'LookupOwnerId'
  • The formula lookups & set a variable called 'DefaultOwnerId'
  • It checks to see if the variable 'LookupOwnerId' has data 
  • And sets the variable 'FinalOwnerId' based on this decision
  • Finally it updates the Account record Owner field with the value in the 'FinalOwnerId' variable

N52 Formula Manager Steps

The following set of steps will set this formula up for you.

  • Create a new formula of type 'Save - Perform Action'
  • Set the Source Entity to 'Account'
  • Set the Source Property to 'Owner Text'
  • Set the Event pick-list field to Create
  • Copy & paste the formula below into the formula description field
  • Click Save
  • Ready to test.

Formula

SmartFlow(

 SetVar('LookupOwnerId', FindValue('systemuser', fullname',[account.new_ownertext],'systemuserid')), 
 SetVar('DefaultOwnerId', FindValue('systemuser','fullname', 'Default UserName','systemuserid')),
 SetVar('FinalOwnerId',   
          if(ContainsData(GetVar('LookupOwnerId')), 
            GetVar('LookupOwnerId'), 
            GetVar('DefaultOwnerId'))),

   SmartFlowReturn(   UpdateRecord('account', 
                             [account.accountid], 
                             SetAttributeLookup('ownerid', 
                                                'systemuser',
                                                GetVar('FinalOwnerId'))
                                        )
                 )
   )

Note 1 : The formula has been written so it easy to understand.

However we can make this formula more efficient by combining the second & third SetVar() function calls. This would save us an extra lookup in relation to the default User ID when the first one exists.

Formula Cleaned Up: 

SmartFlow(

 SetVar('LookupOwnerId', FindValue('systemuser', 'fullname',[account.new_ownertext],'systemuserid')), 

 SetVar('FinalOwnerId',   
          if(ContainsData(GetVar('LookupOwnerId')), 
             GetVar('LookupOwnerId'), 
                      FindValue('systemuser', 'fullname', 'Default UserName','systemuserid'))),

   SmartFlowReturn(   UpdateRecord('account', 
                             [account.accountid], 
                             SetAttributeLookup('ownerid', 
                                                'systemuser',
                                                GetVar('FinalOwnerId'))
                                        )
                 )
   )

Wizard - ClientSideDate

Please see below the wizard you can use to create the ClientSideDate() function call used in this formula. 

 Note 2: to find the value for Equals Value, you will need to go to the Source tab and find the field.   
 

Comments (5)
  • Hello, what does the parameter 'Default UserName', do? I am attempting to modify this to grab a order record and place it on the task entity based on a text order number field. I am not sure what this Default UserName should be changed to to meet my requirments.
  • In the example above 'Default Username' refers to the value in the Full Name field for the record being retrieved by the FindValue function:
     
    FindValue('systemuser','fullname', 'Default UserName','systemuserid')
    This says find the systemuserid for a systemuser record where the value in the fullname field equals Default Username

    The signature of the FindValue function is: 
     
    FindValue('entitylogicalname', 'inputfieldname', 'inputfieldvalue', 'outputfieldname','defaultvalue', 'nolock', 'cacheenabled')
  • Is this referring to the name of the field or the value in the text field? So, looking for systemuser where their name is Default UserName or are you calling the default username from another find value clause? 
  • Basically, there is no default name for system users. 
  • It is referring to the value in the Full Name field. If the user you are trying to find for some reason does not have a value in the Full Name field, then you could use another field e.g. the User Name (logical name is domainname):
     
    FindValue('systemuser','domainname', 'user@contoso.com','systemuserid')

    If you need further help, please email our support team who will be happy to assist - support@north52.com