Question

Trigger doesn't filter properly.

  • 12 February 2024
  • 6 replies
  • 64 views

I have a Notion database that stores information about different tasks. For reference, my Notion database looks like this: Task name (Text), Status (Status), Assignee (Person), Due (Date), Priority (Select), Summary (Text), Explain What You Did (Text), Status Text (Formula), Overdue (Formula), Days Left (Formula). I want to use Notion to automatically send a message to Discord whenever the status of a task changes. For example, if a task goes from “Not started” to “In progress”, I want to notify my team on Discord.

To do this, I used Zaps, and this is how I set up my workflow:

  • The first step is a Notion trigger, which runs whenever the “Updated Database idem” condition is met.
  • The second step is a “Code by Zapier” action, which uses Python to check if the status of the task has changed. It compares the current status with the previous status, and returns True or False accordingly. Here is the code that I use:

    Input: Status Text → Properties Status Text String: Not started

    Code:
    # Define a function to check if the "Status (Text)" column values have changed
    def check_status_change(input_data):
    # Get the current "Status (Text)" value from the input data
    current_status = input_data["Status (Text)"]

    # Get the previous "Status (Text)" value from the previous input data
    # If the previous input data is not available, default to "Not started"
    previous_status = (
    input_data.get("previous_step.Status (Text)") or "Not started"
    )

    # Check if the current "Status (Text)" value is different from the previous value
    if current_status != previous_status:
    # If the values are different, return True to indicate a change
    return True
    else:
    # If the values are the same, return False to indicate no change
    return False

    # Call the function with the input data
    status_changed = check_status_change(input_data)

    # Print the result to the console
    print(status_changed)

    # Store the result in a dictionary for output
    output = {"status_changed": status_changed}
  • The third step is a “Filter by Zapier” action, I set it to only continue if the status_changed output from the previous step is True.
  • The fourth and final step is a Discord action, which sends a message to a specific channel in Discord. The message contains the name and status of the task that has changed.

This is how I set up my Zapier workflow to automate the communication between Notion and Discord. However, I have a problem. The Discord action runs even when I don’t change the status of a task. For example, if I edit the Summary field of a task in Notion, it still sends a message to Discord. I don’t want this to happen. I want the Discord action to run if and only if the variable(s) in the Status Text field change. How can I fix this?


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

6 replies

Userlevel 7
Badge +14

Hi @zapmember29192 

For us to have full context, we would need to see screenshots with how your Zap Filter step is configured.

Also, if you are testing with the Zap ON, then check your Zap Runs history details to see the DATA IN/OUT for each step to help you troubleshoot why it’s passing the Filter step.

The issue is that the condition in my code always evaluates to True, regardless of whether the status_changed variable has changed or not. This is because my code assigns a default value of “Not started” to the previous status of the Status Text variable, if it is not available. Then it compares it with the current status of the variable, which is never equal to “Not started”, and thus the condition is always satisfied. I need to modify my code to retrieve the actual previous status of the Status Text variable, instead of using a default value, so that the condition only evaluates to True when there is a change in the status. I tried removing the “Not started” default value, but then the code doesn’t even run, because it doesn’t pull any data.

This is how my “Filter by Zapier” looks like:
 


So how would I go about doing what I actually want to do, which is having the Discord action run if and only if the variable(s) in the Status Text field change?

Userlevel 7
Badge +14

@zapmember29192 

If the Code step is always evaluating to true, then the Code step logic would need to be fixed.

Try asking ChatGPT for help fixing/optimizing the code.

I am the developer of this code. ChatGPT suggested to remove the “Not started” value in the input_data.get(“previous_step.Status (Text)”) or “Not started” line, but that does not work for me. I need to pull the data from the input_data variable and compare it, as part of the algorithm I’m designing, and ChatGPT does not understand that the function must pull data, it only understands that I need to fix an error and hap-hazardly hard-codes a solution into the code. As I explained, removing the or Not starter causes the following error:

Traceback (most recent call last):
      File “<string>”, line 28, in the_function
NameError: name ‘output_data’ is not defined

Can you please advise me on how to achieve what I want, which is to trigger the Discord action only when the variable(s) in the Status Text field change? I appreciate your assistance and expertise as Zapier support, and I would expect Zapier support to know their own product and how to fix issues with it :)

UPDATE: So I updated my code to be the following:

 

"# Define a function to check if the "Status (Text)" column values have changed
def check_status_change(input_data):
# Get the current "Status (Text)" value from the input data
current_status = input_data["Status (Text)"]

# Get the previous "Status (Text)" value from the input data of the previous step
# If the input data is not available, default to "Not started"
previous_status = (
input_data.get("Value", "Not started")
)

# Check if the current "Status (Text)" value is different from the previous value
if current_status != previous_status:
# If the values are different, return True to indicate a change
return True
else:
# If the values are the same, return False to indicate no change
return False

# Call the function with the input data
status_changed = check_status_change(input_data)

# Print the result to the console
print(status_changed)"

Now the function runs, but status_changes is always false because the value never changes, it compares itself, and of course the same value never changes.

My question now is, which Zapier “steps” do I need to implement into my workflow so that it can compare the values of the Status Text field to see if they’ve changed or not? Do I need to implement Storage by Zapier? How would I go about doing it? I would greatly appreciate a detailed response and I value your time.

Userlevel 7
Badge +14

@zapmember29192 

If the Zap trigger data does not include before/after values for you to use to compare, then you would have to create and maintain a lookup table to use in the Zap.

 

Very good advice Troy, excellent, I appreciate the general guidance. Now comes the question: how would I integrate a Lookup table in my specific workflow?