Is it possible to verify if variable is defined in storeEval?


#1

Hello, I receive the next error message: [error] variable “HOURLY_PICKUP” is not defined

Is it possible to verify with javascript inside storeEval if variable is undefined to not execute this storeEval?

I try with this code, but it does not work:
if ((typeof ${hourly_pickup} !== ‘undefined’) && “${hourly_pickup}” != “#nomatchfound”) {(res0 = “${hourly_pickup}”);} else {res0 = “”;} res1 = res0 +"\n"; if ("${hourly_pickup_address}" != “#nomatchfound”) {(res2 = “${hourly_pickup_address}”);} else {res2 = “”;} res3 = res2 +" " + res1;

Thank you!


#2

Why not define your variable before running your code?
Eg with store | | hourly_pickup?


#3

I don’t declare variables that I don’t need to reduce time of execution, because my macro is quite long, so I prefer just to use inside storeEval thing like this:

if ("${useful_info}" == “#nomatchfound” || “${useful_info}” == undefined)
{res0 ="";}
else {res0 = “${useful_info}” + “\n”;} ;
if ("${hourly_description}" == “#nomatchfound” || “${hourly_description}” == undefined)
{res1 = res0;}
else {res1 = res0 + “${hourly_description}” + “\n”;};

It says that if “${hourly_description}” is undefined just execute {res1 = res0;} and continue.
But the problem is that in case if “${hourly_description}” is undefined it goes back and execute a peace of macro again and again, But I just need to macro continue to go on if there is some undefined varibles.
This realy helps to reduce execution time and length of the macro.
I know that I can use #goto with onError but it’s adding at least three lines in the macro.

Thank you!


#4

I need to “type” the value of this variable later!
If I define it with some placeholer value it wil be typed but I need a real value if it exists,
but if I define it with real value like this ${hourly_pickup}, if this variable is undefined it will trigger error.
So there is no sense to do what you say.


#5

There is actually no difference.
Declare variable. Check if length > 0.
And it is exactly the same.
You will not save anything on the contrary you will spend numerous minutes searching online for a piece of code that only you want to have.
I gave you a workaround. Surely It’s up to you use it or not. Good luck.