Can I check if a variable exists in Make without initializing it?

:bullseye: What is your goal?

I want to have a filter in Make that only passes if a variable hasn’t been set yet. My scenario later updates this variable multiple times, but I’d like to skip the initial “Set variable” module to save credits if it’s possible.

:thinking: What is the problem & what have you tried?

Creating a filter and manually entering just the variable name

1 Like

Hi @ComfortableMedia6,

You cannot read the value of a variable if that variable is not set. It is unmappable in a filter, or rather undefined, because it was not declared yet.

If you do not declare it with a Set Variable, how can you check if it exist? It would always be non-existent?

Curious to what your setup looks like, feel free to share the scenario here. You can do this safely from the Scenario Builder: Scenario sharing - Help Center

Cheers,
Henk

Hi @Henk-Operative,

I’m not trying to read the variable’s value — I’m trying to check if the variable exists at all. My expectation is that if I haven’t declared it with a Set Variable module, the filter or condition should detect that it doesn’t exist.

For some reason, when this condition is met, the scenario doesn’t continue.

I’ve created this barebones example with a router. In it, if the first route doesn’t run, Variable2 never gets set. The scenario should then recognise that Variable2 doesn’t exist and continue to set Variable3 on the second route — but it doesn’t.

I’m wondering if this is a limitation of Make, or if I’m missing something in my setup.

I’m doing this as part of the Magic Formula method and just want to confirm whether this approach is possible.

Hello,

If I understand your problem correctly - yes. It should be possible but highly inefficient.

Option 1.
Use custom variables available in Pro, Teams and Enterprise plans.
But it will require an extra operation to reset the variable after the last run - so you will end up with the same usage but on a more expensive plan.

Option 2.
Create a router and filter flow based on the existence of a variable. But in that case you will have to use Get Variable.

So yes - there are ways to do that but they won’t save you operation costs.


Meanwhile you added additional information.

It won’t work in your configuration.

Why?

Module 1 creates variable 1
Router filters flow based on variable 1
If true → create variable 2
And for variable 3 you are referring to variable 2 which won’t ever exist at this stage.

So to achieve this you must add “get variable” (and get Variable 2) before Variable3. Now you are able to filter based on variable2.

Take a look here:

Hi @ComfortableMedia6,

The issue with the mapping of each route is that you perform a condition on a string. It is literally checking if the text VariableN doesn’t exist. And that condition always renders to false because a) the string exists for path 2 or b) the text is not equal to false for path 1, therefore the scenario doesn’t continue.

Now variables in Make exist in the context of a module or the path after you have set or fetched it, but not in the scope of the scenario.

Now if I get the variable first, whether it exists or not, I can reference it:



Cheers,
Henk

Thank you both for your responses. As I mentioned, I was hoping to skip the initial “Set Variable” module to save credits, but from what you’ve explained, it seems this isn’t possible.

I’m not entirely sure why — in most programming environments, checking whether a variable has been defined is a very basic operation, so it feels a bit surprising that it’s not allowed here.

Either way, I just wanted to clarify. Thanks again for your help!

If you have a module that accesses the variable before the filter then sure, you can map it from there.

But if you don’t have that, then there is no way to check it. Even if you declare it afterwards.

You still need at least a Get Variable module before the filter. Then you can have your set variables after the router.

Understood, thank you. I just don’t understand why there isn’t a condition that allows the filter to pass when no variable is found at all. Hopefully you see what I mean.

There is no variable to be found though. If there is no module either declaring the variable or retrieving it before the filter, you can’t map it inside for checking.

The other option is to use the custom variables available on higher tier plans. Then you can access it regardless if it is being set after the filter. I think that this is the variable type you are thinking of, as this one exists regardless of what the scenario does with it.

The thing is that in Make, a variable is not scoped to the script/scenario as a whole, but exists inside a module. That is why you can only access the variable while mapping when you are in the same path (thus you can access outputs of preceding modules), or if you Get Variable’d it.

So in order to check if a variable is defined, Make expects you to reference where it was defined (or Get Variable’d) by pointing to it in the Make syntax: {{1.defined_here}}.

Hi @ComfortableMedia6 ,

In Make, it isn’t possible to check whether a variable exists without initializing it first. Variables do not exist by default, and filters can only evaluate values that have already been created. Because of this, a variable must be set at least once (even with an empty value) before it can be used in a filter.

Additionally, a filter can only reference a variable if it has already been accessed earlier in the execution. If there is no module before the filter that retrieves the variable (such as a Get variable module), the filter has nothing to evaluate. Declaring or setting the variable later in the scenario does not make it available retroactively, so at least one operation (Set or Get variable) must occur before the filter.

This behavior follows Make’s variable lifecycle and execution model, which requires variables to be initialized or retrieved before they can be evaluated in filters.

Best regards,
Msquare Automation
Platinum Partner of Make
@Msquare_Automation

As mentioned - Make does not store variables in script/scenarios.

There is one exception - there are custom variables available which are stored for the organization or team.

They are available on Pro, Teams and Enterprise plans.

But in your use case, you will have to clear their values after each run.

For details please refer to: