A Simple Single Step Round Robin with Storage by Zapier and Code By Zapier

  • 8 April 2022
  • 0 replies
  • 1338 views

Userlevel 7
Badge +12

Zapier is great platform to use to take data from different lead sources and create follow up tasks or contacts in your company’s CRM. When creating these records, you can often assign the contact or task to a specific staff member so that they are in charge of the lead. But what to do if you have multiple employees working on leads in your company and you want to have a way to evenly distribute the leads as they are entered into your CRM or route them by email? This tutorial will walk you through an easy 1 step round robin set up using Storage by Zapier and Code by Zapier. 

Step 1: Authenticate a storage by Zapier account. Never used storage by Zapier? No problem! It’s a breeze to get set up. Head over to your Zapier App Connections Page: https://zapier.com/app/connections 
Click on ‘Add Connection’ then search for ‘Storage by Zapier’. 

A new window will pop up with a prompt to enter your store secret. You can use a UUID generator for this: https://www.uuidgenerator.net/version4. Make note of your UUID as you will need it again momentarily. 
 


Step 2. Once you’ve created a UUID and connected your Storage by Zapier account you can head to your Zap. You will need a Code by Zapier Step > Run Javascript (Code provided below)


On the set up action dropdown, you will need to configure your team members! Generally, i put the name on the left and the email on the right but both values will be returned to you. So, if the name is not needed or you are inputting data into your CRM you may need to put the user id instead of the email address to map the values correctly.. however in this example we will just be sending an email to the sales person.

Adding or removing users from the round robin is as easy as adding or removing the input fields in this step. 

Next we will configure the code block (the only thing you need to change is the Storage UUID). You will need to insert your UUID in the first line of the code where it says INSERT YOUR UUID HERE. Otherwise, you just need to copy the code provided into your code block and test action.

let secret = "INSERT YOUR UUID HERE"

let length = Object.values(inputData).length;

//Instantiate connection to Round Robin Storage
var store = StoreClient(secret);

//get UP NEXT
let up_next = await store.get('up_next');


//figure out who after current up next
let names = Object.keys(inputData);
let ids = Object.values(inputData);
let totalSalesPeople = ids.length;


var currentIndex = names.indexOf(up_next);

//If name not in list of names. reset to first name in list
if (currentIndex == -1) {
up_next = names[0];
currentIndex = 0;
}
//get id of who is up next
var upNextId = ids[currentIndex];


//get next up index
var nextUp;
if ((currentIndex+1) < ids.length) {
nextUp = currentIndex+1;
} else {
nextUp = 0;
}

//set who is up next for next time
await store.set('up_next', names[nextUp]);

return {
up_next_name: up_next,
up_next_id: upNextId,
}

You will see in the screenshot below i have replace the value “INSERT YOUR UUID HERE” with my actual uuid i used to create the storage connection 



Voila! Each time Zapier runs the code block it will automatically assign to the next person in the list and when it gets to the final person, it just loops back to the top of your input blocks. 


Step 3. Now i can map the values from this step into my email step evenly distributing my leads!


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.