Skip to main content

problem solved

Part of the issue is that process.env is not supported by Code by Zapier steps. That’s for Zapier app developers. You’ll want to use Storage by Zapier instead.

What you’re trying to do is called a “Round Robin” technique. You can search this forum for some previous examples of Round Robin code. I’ve also included my preferred method below.

output = {oldValue: "", newValue: "", selectedIndex: "", selectedName: ""};

// Call Zapier's storage and share the UUID4 secret (get a UUID4 secret at https://www.uuidgenerator.net/version4 if needed)
const ROUND_ROBIN_STORAGE = StoreClient(""); // <- Place your unique UUID4 between double quotes here

// Assign list of assets to LIST
const SELLERS = s'Carla', 'Elena', 'Valentina'];

// Get the existing value of ROUND_ROBIN_STORAGE
output.oldValue = await ROUND_ROBIN_STORAGE.get('increment');

// Add 1 to it
output.newValue = output.oldValue + 1;

// Set the new value in ROUND_ROBIN_STORAGE
await ROUND_ROBIN_STORAGE.set('increment', output.newValue);

// Use modulo to execute round robin list selection
output.selectedIndex = (output.newValue % SELLERS.length);

// Determine name of selected asset
output.selectedName = SELLERSaoutput.selectedIndex];

If you have difficulty implementing this, I would highly recommend hiring a Zapier Expert to help you out.


Hi @Angelo, if you wouldn’t mind, it’s beneficial to the community if you leave your original post up and write out the solution you ended up using instead of changing your post to “problem solved”. That way, if somebody encounters this issue in the future, they can search the forum and find the solution instead of having to post the same question again.


Hi @Angelo, if you wouldn’t mind, it’s beneficial to the community if you leave your original post up and write out the solution you ended up using instead of changing your post to “problem solved”. That way, if somebody encounters this issue in the future, they can search the forum and find the solution instead of having to post the same question again.

Hi Tod,

I'm new to the community and I think you're right in leaving the original post, tomorrow when I have time I'll rewrite it all.

I will also try your great solution.

I finally used this method to solve the problem

 

 


@Angelo Lionel’s solution is actually very similar to mine in many ways, but it is less efficient, since it uses multiple steps with built in Zapier apps instead of a single code step :)


@Angelo Lionel’s solution is actually very similar to mine in many ways, but it is less efficient, since it uses multiple steps with built in Zapier apps instead of a single code step :)

I want to test your code tomorrow to do fewer steps


@Angelo Lionel’s solution is actually very similar to mine in many ways, but it is less efficient, since it uses multiple steps with built in Zapier apps instead of a single code step :)

I can no longer edit the post, write my problem below

 

Good morning everyone, I have a problem that I can't solve.

I created a javascript code like this below:

// Get the current value of currentIndex from the environment variable
const currentIndex = parseInt(process.env.currentIndex || 0);

// Define an array with sellers
const sellers = s"Carla", "Elena", "Valentina"];

// Add a log to print the value of currentIndex
console.log("Value of currentIndex:", currentIndex);

// Calculate the index of the next seller
const nextIndex = (currentIndex + 1) % sellers.length;

// Add a log to print the value of nextIndex
console.log("Value of nextIndex:", nextIndex);

// Save the new value of currentIndex to the environment variable
process.env.currentIndex = nextIndex;

// Add a log to confirm saving the new value
console.log("New currentIndex value saved:", nextIndex);

// Return the current seller as output
output = {
   sellerCurrent: sellersecurrentIndex]
};


what this code should do is select the first seller for me with the first interaction with the zapier flow therefore starting from Carla, then after all the zapier has been carried out and another customer arrives who performs the whole zapier flow it should click in sequence to Elena, to then end up with Valentina and start all over again with Carla.

I need all this to assign a seller in sequence to each customer who completes the zapier, so when I receive outputs from the javascript code with the name of the seller, I can use that data to insert it into a slack chat to ensure that each customer it is assigned on the slack chat to each seller in sequence.

example

Guys, a new lead for Movie Archetypes
Name: Saurina
Surname:
Email: test@gmail.com
Cell. 33333333
Assigned to Carla

this is what should appear on the slack chat, everything works, I can assign the seller to the slack chat and insert the seller on close thanks to the javascript code outputs

the problem is that I tried different javascript or pythone codes but these problems occur:

- the code freezes and always remains on Carla and does not proceed forward in sequence with Elena and Valentina.

- The code works and changes the name of the seller but it chooses them at random and does not go in sequence and sometimes it even chooses them 3 or 4 the same times.

I also created a webhoock by testing it on pipedreams before the javascript code to give it a currentIndex of 0, but it still doesn't work, I'll attach some screens

Thanks so much for the replies, I'm going crazy