How to avoid error "Unable to locate var" when the variable is not created?

Options

Hi,

My function stack, in a loop, sometimes create a variable object called "final_variant_records_with_errors". Sometimes it doesn't (this is intended).

I need to reference "final_variant_records_with_errors" later in the loop, only if has been created.

The problem is, if it was not created, Xano would return error "Unable to find var".

I tried this without success:


Is there a solution to this that doesn't involves creating an empty variable for each loop?

Any help would be appreciated. Thanks!

Answers

  • Cameron B
    Cameron B Member, Administrator

    ADMIN

    Options

    Using a GET filter is going to be the best way to get a value in a chain while simultaneously preventing errors for the value if it doesn't exist. What you're doing looks like the best way to achieve this. But just so I understand correctly, you want to

    1) Loop through your data
    2) Sometimes create, and sometimes not create, a final_variant_records_with_errors object variable.
    3) Reference the final_variant_records_with_errors object variable if it's been created.

    You can continue to use the GET Filter, but it also sounds like that within this function stack, a conditional can be used to route the logic based on the argument that the final_variant_records_with_errors object variable exists.

    Let me know if this helps at all or what else I can assist with :)

  • pachocastillosr
    Options

    Thanks for replying @Cameron B . You understand correctly.

    Regarding your suggestion about the conditional, which would be the condition that you suggest?

    I've tried using conditional IF "final_variant_records_with_errors" is not empty, but that can't run if "final_variant_records_with_errors" do not exists (since it has nothing to evaluate), so it returns the same error "Unable to locate var".