Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
MVP
MVP

Alt() works differently in script and in front end

Consider the following script fragment:

Set x1 = 1;

Let x2 = 2;

Let z1 = Alt(x1, 100);

Let z2 = Alt(x2, 200);

Let e1 = IsNum(x1);

Let e2 = IsNum(x2);

This produces the following results:

Capture.PNG

Notice that the Alt(x1, 100) considered x1 to be non-numeric, whereas IsNum(x1) sees x1 as numeric. Furthermore, in the front end, we get this:

Capture.PNG

So x1 is being seen as numeric by Alt() and IsNum() in the front end expressions, and in the script it is considered numeric by IsNum(), but non-numeric by Alt().

In the case where this behaviour was observed, the Set x1  = 1 expression is dynamically generated from a configuration file. The Alt() was required to provide a default if the configuration file did not have a definition of x1.

The workaround is to change the config loader to generate the values with Let, but if that is not an option, use an expansion:

Let z1 = Alt($(x1), 100);

Version 11.2 SR15 11.20.13405.0

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
3 Replies

Re: Alt() works differently in script and in front end

I'm not sure if this behaviour is really unexpected then Set x1 = 1; assigned a string to the variable and Let x2 = 2; creates an dual-value with 2 as string and 2 as numeric value. Therefore differ the alt-results by the z-variables. And I think isnum() instead will be evaluate it's input-value and at first check if the value is an (valid) dual-value and if it's not then it will check if the string-representation could be evaluated as number - and in this case both checks on the e-variables will be true.

Further I think the front-end treated the x1 variable as number because it sees it just as 1 and not as '1'.

- Marcus

MVP
MVP

Re: Alt() works differently in script and in front end

Marcus

That's my interpretation of the behaviour too (and that's why Let x = 1 does not have the problem) - it just seems inconsistent to me and it caused a hard to track down bug. IMO Alt() should act like IsNum() does and be the same in the script and in the front end.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

Re: Alt() works differently in script and in front end

Maybe hic could give some backgrounds if it's behaved expectedly or not and why there are differences between alt() and isnum().

- Marcus

Community Browser