This guide will help to walk you through building a complex if/then formula in order to perform Lead assignment by State.



Setup:

You really should perform the following steps in a programming text editor. Do not use MS Word. Download VS Code or Sublime or Notepad++ or something. If you must, use plain notepad/textedit.


Parameters:

In the workflow, create 2 parameters:


1. The State : {P0}

2. The currently assigned user id- Relation Parameter -> Assigned User -> ID : {R0}


The Steps:

Build an Equal Statement for each State:

Go ahead and break them up by User

//User 1
{equal({P0} ; IA)}
{equal({P0} ; MN)}
{equal({P0} ; WI)}

//User 2
{equal({P0} ; KS)}
{equal({P0} ; NE)}
{equal({P0} ; SD)}
{equal({P0} ; IL)}

//User 3
{equal({P0} ; OH)}
{equal({P0} ; IN)}
{equal({P0} ; ND)}
{equal({P0} ; PA)}



Combine the statements into Or pairs:

  - Cut/paste the Equal statement into "ITEM1" or "ITEM2" in the template below

  - If a user has an odd number of States, then place a "0" in "ITEM2"


// {or(ITEM1; ITEM2)}

//User 1 (notice how the last pair has a zero)
{or({equal({P0} ; IA)}; {equal({P0} ; MN)})}
{or({equal({P0} ; WI)}; 0)}

//User2
{or({equal({P0} ; KS)}; {equal({P0} ; NE)})}
{or({equal({P0} ; SD)}; {equal({P0} ; IL)})}

//User3
{or({equal({P0} ; OH)}; {equal({P0} ; IN)})}
{or({equal({P0} ; ND)}; {equal({P0} ; PA)})}


Combine the groups again if needed:

  - You must end up with one line per User.

  - Again, if there are odd numbers of items, place a 0 in "Item2"


//Combine the groups until you end up with one statement per User

//User 1
{or({or({equal({P0} ; IA)}; {equal({P0} ; MN)})}; {or({equal({P0} ; WI)}; 0)})}

//User2
{or({or({equal({P0} ; KS)}; {equal({P0} ; NE)})}; {or({equal({P0} ; SD)}; {equal({P0} ; IL)})})}

//User3
{or({or({equal({P0} ; OH)}; {equal({P0} ; IN)})}; {or({equal({P0} ; ND)}; {equal({P0} ; PA)})})}


Start building the If/Then blocks

  - Use the Template below

  - Place the User's Name in the "USERID" section


// Start building an IF/Then for each user

{ifThenElse(CONDITION; USERID; ELSE)}

{ifThenElse(CONDITION; Jared; ELSE)}
{ifThenElse(CONDITION; Brad; ELSE)}
{ifThenElse(CONDITION; Tim; ELSE)}


Set the Fallback value in the Final "ELSE" block:

  - In our case, we're going to fallback to the currently set Assigned user id which we have saved as {R0}

{ifThenElse(CONDITION; Jared; ELSE)}
{ifThenElse(CONDITION; Brad; ELSE)}
{ifThenElse(CONDITION; Tim; {R0})}


Copy the OR statements into the "CONDITION" blocks:

  - Make sure these are on one line per user (even if this webpage wraps the text)

{ifThenElse({or({or({equal({P0} ; IA)}; {equal({P0} ; MN)})}; {or({equal({P0} ; WI)}; 0)})}; Jared; ELSE)}
{ifThenElse({or({or({equal({P0} ; KS)}; {equal({P0} ; NE)})}; {or({equal({P0} ; SD)}; {equal({P0} ; IL)})})}; Brad; ELSE)}
{ifThenElse({or({or({equal({P0} ; OH)}; {equal({P0} ; IN)})}; {or({equal({P0} ; ND)}; {equal({P0} ; PA)})})}; Tim; {R0})}


Take the last line and cut/paste it into the "ELSE" block of the one above. Repeat until all are on one line:


{ifThenElse({or({or({equal({P0} ; IA)}; {equal({P0} ; MN)})}; {or({equal({P0} ; WI)}; 0)})}; Jared; {ifThenElse({or({or({equal({P0} ; KS)}; {equal({P0} ; NE)})}; {or({equal({P0} ; SD)}; {equal({P0} ; IL)})})}; Brad; {ifThenElse({or({or({equal({P0} ; OH)}; {equal({P0} ; IN)})}; {or({equal({P0} ; ND)}; {equal({P0} ; PA)})})}; Tim; {R0})})})}


Map this to the "Description" field and test:


After testing, replace the User names (Jared, Brad, Tim) with their ID's


Finally, map the formula to the Assigned User field and test.