This topic was automatically generated from Slack. You can find the original thread here.
I’m trying to consecutively iterate over 4 values - the use case here is assigning leads, to make sure no one gets left out. Using random it’s too possible that a few get assigned to the same person in a row.
I’m looking into the variable which I can pull, but even using os can’t seem to figure out how to change within a Python step in a workflow.
Any suggestions for storing a value and updating it that I can access across workflow runs?
I’m trying to consecutively iterate over 4 values - the use case here is assigning leads, to make sure no one gets left out. Using random it’s too possible that a few get assigned to the same person in a row.
I’m looking into the variable which I can pull, but even using os can’t seem to figure out how to change within a Python step in a workflow.
@U05A7KLNALC Any suggestions for storing a value and updating it that I can access across workflow runs?
To achieve your goal of consecutively iterating over 4 values and ensuring no one gets left out, you can use Pipedream’s Data Stores. Data Stores allow you to store and update values across workflow runs. Here’s how you can do it using a Python step in a Pipedream workflow: 1. Create a Data Store: First, create a Data Store to hold the current index of the lead assignment. 2. Update the Data Store in a Python step: Use a Python step to retrieve the current index, update it, and store it back in the Data Store. Here’s an example of how you can implement this: def handler(pd: "pipedream"): # Access the data store under the pd.inputs data_store = pd.inputs["data_store"] # List of leads leads = ["Lead 1", "Lead 2", "Lead 3", "Lead 4"] # Retrieve the current index from the data store, default to 0 if not set current_index = data_store.get("current_index", 0) # Assign the lead based on the current index assigned_lead = leads[current_index] # Print the assigned lead (or use it in your workflow) print(f"Assigned Lead: {assigned_lead}") # Update the index for the next run next_index = (current_index + 1) % len(leads) # Store the updated index back in the data store data_store["current_index"] = next_index # Return the assigned lead for use in future steps return {"assigned_lead": assigned_lead} ### Explanation: 1. Access the Data Store: The data_store object is accessed from pd.inputs["data_store"]. 2. Retrieve the Current Index: The current index is retrieved from the Data Store. If it doesn’t exist, it defaults to 0. 3. Assign the Lead: The lead is assigned based on the current index. 4. Update the Index: The index is incremented and wrapped around using modulo operation to ensure it stays within the bounds of the list. 5. Store the Updated Index: The updated index is stored back in the Data Store for the next workflow run. This approach ensures that the leads are assigned in a round-robin fashion, and no one gets left out.