Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
rai-jmcpheeters
New Contributor III

Subroutine within If Statement

Hi everyone,

I'm marking this as a potential bug here so that my partner can reference it. I'm running Qlik Sense Server - April 2018.

Attached is an example of code where I load a subroutine at the beginning of my script based on a variable and then call the subroutine. In the first case, where the calling of the subroutine is within the same If statement, code execution completes without issue. However, if you switch the variable value to load the other subroutine, which is called further down in the script, you get a Semantic Error. Both subroutines are identical (empty) so it doesn't have anything to do with the code within them.

Does anyone know if this is a bug or if Qlik intentionally limits the retention of the subroutine code to the bounds of an If statement?

Best regards,

Justin

Tags (2)
3 Replies
MVP & Luminary
MVP & Luminary

Re: Subroutine within If Statement

It strikes me as a bug.

-Rob

Partner
Partner

Re: Subroutine within If Statement

I believe it is a bug as well.  Tested in June 2018 and still doesn't work. 

Here's a work-around.  Set a variable to the filename and then do the include outside the if statement:

Let vTrueFalse = -1;

//Let vTrueFalse = 0;


If $(vTrueFalse) then

      let FileName = 'SubRoutine1.txt';

Else

      let FileName = 'SubRoutine2.txt';

EndIf


$(Include=[lib://AttachedFiles/$(FileName)]);


If $(vTrueFalse) then

      Call SubRoutine1;

   

Else

      Call SubRoutine2;


EndIf

Highlighted
Partner
Partner

Re: Subroutine within If Statement

Here's another reference to the same issue with an explanation:  SUB inside IF ... THEN statement