Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

4 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

It strikes me as a bug.

-Rob

gwoodard
Partner Ambassador
Partner Ambassador

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

gwoodard
Partner Ambassador
Partner Ambassador

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

cbushey1
Creator III
Creator III

I am really surprised this issue hasn't been taken up by R&D to fix yet. 

Anyone know how we can get this bug in front of someone at Qlik?