Friday, February 5, 2010

Automatic Lead Assignment Using Workflows

The problem with using workflows for lead assignment is you don't know who you sent the last lead to. However, you can get around this in a couple of ways.

Method 1: Code
I'm not much of a coder so I figured I'd try to achieve it without using plugins or jscript

Method 2: The cheeky use of entities to store values
To keep track of who we last sent a lead to, we're going to create a new entity and create a record for the variable storage. Let's call the entity 'RoundRobin'. We have a few options here.
  • We could use the ownership relationship to store the next user to receive a lead
  • We could set up a new N:1 relationship to the user entity
  • We could add an attribute and store a value there

In my case I've set up an attribute.









I've also set up a 1:N relationship to Leads (they're called Enquiries here but they are just renamed Leads, I promise).

Now the tricky bit, the workflow. The steps of the workflow are:

  • Link the lead to your one RoundRobin record
  • If the attribute is 'a', assign the Lead to User1 and update the attribute to 'b' (in the case of using a relationship to the users, simply reassign it)
  • If the attribute is 'b', assign the Lead to User2 and update the attribute to 'a'

Here is one I prepared earlier:




In this case I have it as On Demand but with workflows being asynchronous, this tends to act a little weird (basically a bunch of Leads get assigned before the attribute has a chance to change). However, if you run it on the creation of the lead, it works fine assuming there is a reasonable time between lead creations.

3 comments:

Leon Tribe said...

One recent quirk that has recently been revealed is that the steps do not strictly wait for the last step to finish before starting the next one. The upshot of this is the linking to the counter entity may not complete before the 'if' statement kicks in. If this is the case, simply put a wait condition between the first update and the if statement.

You can wait a fixed amonut of time e.g. 1 minute or try something more exotic like wait until the lead lookup to the counter entity has data. I have not tested this second one but it should work.

Thanks to Jennifer Towers for pointing this one out and persevering until we found out the problem.

Garrett W. said...

I'm wondering if this is possible:

I want to create a custom entity that contains sales territories that are assigned to various users so I can easily update them. Then I'd like my leads to be automatically assigned to users based on the territory that is assigned to them in that entity. I can't figure out how to get a workflow to check or match the values in the custom entity against the lead and assign it to the owner of the record in the custom entity.

Leon Tribe said...

So this is how you do it. You create a new territory entity with user/team ownership with Lead as a child entity. In the workflow you use the Assign step and click the 'Set Properties' button. Click inside the white text box and then in the Dynamics value section drop down Lead and select your territory entity with the value as owner.

If you have any troubles, let me know.