Skip to main content

In Zapier code I want to check if query.XXX or query.YYY is part of the received data.

 

It is super stupid made, but it cant be fixed → so I can’t just take it as one input data.

 

So how to check if query.XXX is part of the request

 

Thank you

Hi @RasmusMadsen 

Good question.

Perhaps you can use a Filter step instead of a Code step: https://zapier.com/apps/filter/help

Otherwise, provide more context about how you are trying to configure your Zap steps.


Thank you for the reply @Troy Tessalone → unfortunately I can't use filter.

The system I use is super stupid, but if a product is selected it shows a value.

If the product is not selected, it is removed from the data (response).

So I have to somehow check if the name exists in response and then define a variable.

And I have to do that on 10 products.

Does it make sense?


if var1 is in response:var1 = value1If var1 is not in response:Do nothingAlso for the next product

if var1 is in response:var1 = value1

If var1 is not in response:Do nothing

Also for the next product


@RasmusMadsen

Sounds like a series of IF statements would work.

 

This related article might provide guidance.

 

If you need help configuring the Code, consider hiring a Certified Zapier Expert: https://zapier.com/experts/automation-ace


IF statement search for value not the query. So in the article I need to know if it is “Joe”. The value on my query is a random number.

 

Any other ideas?

 

Thank you so much


@RasmusMadsen 

We’d need to see screenshots with the data you are trying to use in the Code step to have enough context.


Thank you - let me try 🙌

 

Data example 1:

 

The check on if those exist (12 in total)
querystring__Komplet_Polering

querystring__Bundbehandling

querystring__Maling

querystring__Krsel

querystring__materialer_og_miljafgifter

 

If exist in query I need to define a variable with the value. 

So Komplet_Klargring = 6195


@RasmusMadsen 

Each of these are variables with values that can be mapped to following Zap action steps using the custom mapping option.

 

 


Not as I see it.

Sometimes the endpoint is given:

querystring__Komplet_Polering

querystring__Bundbehandling

 

Next time:

querystring__Bundbehandling

querystring__Maling

 

How do set Komplet_Polering to 0 in the second?


@RasmusMadsen 

In that case, you’d need to map every possible variable as an input in a Code step.

Then in the Code step you can do this.

EXAMPLE

Inputs

Var1 = {Var1}

 

Code (JavaScript)

let Var1 = inputData.Var1 || 0; // set default to 0 if no input variable exists

let Var1 = inputData.Var1 || “”; // set default to “” if no input variable exists

let Var1 = inputData.Var1 || null; // set default to null if no input variable exists

let Var1 = inputData.Var1 || false; // set default to false if no input variable exists


Thank you → I am getting closer! Hopes it is okay to ask the last one. 

 

What am I missing here:

 


@RasmusMadsen 

Help article about how to use the Code step: https://help.zapier.com/hc/en-us/articles/8496197098253-JavaScript-code-examples-in-Zaps


If any other can see my error I will give virtual high-five 🎉