Qlik Community

Qlik Sense App Development

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

Highlighted
jepeerik
New Contributor III

Sub from Include not found when Call is outside IF-statement

I want to Include a file containing a Sub. I include this within an IF-statement.

When the Call-statement is executed within the IF-statement, the Sub if found and executed. When the Call is outside the IF-statement, the Call is giving an error saying that the Sub is not found.

I've tested it with an Include and Must_Include.

Any clue?

Script for loading the Include file and the IF and Call statements:

IF 1=0 THEN

            TRACE 'Test IF';

ELSE

            TRACE 'Test ELSE';

$(Include=lib://FolderQlik\TestInclude.qvs);

Call TestInclude;               //This Call is working fine

END IF

TRACE 'Test outside IF';

Call TestInclude;                         //This Call is generating an error

Contents of the Include file:

TRACE 'preSUB TestInclude';

SUB TestInclude

            TRACE 'SUB TestInclude';

END SUB

Sharing knowledge increases your knowledge
1 Solution

Accepted Solutions
andrey_krylov
Valued Contributor

Re: Sub from Include not found when Call is outside IF-statement

8 Replies
andrey_krylov
Valued Contributor

Re: Sub from Include not found when Call is outside IF-statement

jepeerik
New Contributor III

Re: Sub from Include not found when Call is outside IF-statement

Thanks Andrey for your response.

Now I know why it isn't working. I also noticed this behaviour with the FOR-loop.

So, the reason why I actually want to do this is because I dynamically want to Include all QVS-files (except 1, so therefore the IF-statement) within a folder and therefore I need a FOR-loop. So that will not work this way.

Maybe you have another solution?

Thanks.

Greetings,

Jörgen

Sharing knowledge increases your knowledge
andrey_krylov
Valued Contributor

Re: Sub from Include not found when Call is outside IF-statement

Hi, Jörgen. Maybe, for dynamical Include - something like this

IF 1=0 THEN

           TRACE 'Test IF';

            vScript = '';

ELSE

            TRACE 'Test ELSE';

vScript = 'Include=lib://FolderQlik\TestInclude.qvs';

$($(vScript));

Call TestInclude;               //This Call is working fine

END IF

TRACE 'Test outside IF';

$($(vScript));

Call TestInclude;    

jepeerik
New Contributor III

Re: Sub from Include not found when Call is outside IF-statement

Thanks. That's indeed the trick to get it outside the IF-statement.

But I'm stuck with the FOR-loop. I need a loop to dynamically load all qvs files from a folder, and as far as I know that's something I can't fix without the loop or outside the loop.

Greetings,

Jörgen

Sharing knowledge increases your knowledge
andrey_krylov
Valued Contributor

Re: Sub from Include not found when Call is outside IF-statement

I don't get exactly your reqourment. Can you share more detailed code, Jörgen?

jepeerik
New Contributor III

Re: Sub from Include not found when Call is outside IF-statement

I have several qvs files in a folder and I want to Include them all, except for 1 (@Calls.qvs).

I want to do this dynamically, because I've got a lot of folders with different qvs files.

These qvs files containing SUB routines. After Including all those files, I want to Call those routines on another place.

Underneath my code to Include those files. This is working fine, but the as discussed before, I can't Call a subroutine outside the IF statement and/or FOR loop.

For the IF-statement we've got a workaround. Now I need the work around for the FOR loop.

//Load each qvs file in the app folder, excluding @Calls.qvs

FOR EACH vIncludeFile in FILELIST('$(vFolder)*.qvs');

      IF '$(vIncludeFile)' = REPLACE('$(vFolder)@Calls.qvs','\','/') THEN

          //Do Nothing

      ELSE

           $(Must_Include=$(vIncludeFile));

      END IF

NEXT vIncludeFile

CALL SubRoutineFromQVS          //which is failing

Sharing knowledge increases your knowledge
andrey_krylov
Valued Contributor

Re: Sub from Include not found when Call is outside IF-statement

Oh, Maybe this

vString = '';

FOR EACH vIncludeFile in FILELIST('$(vFolder)*.qvs');

      IF '$(vIncludeFile)' = REPLACE('$(vFolder)@Calls.qvs','\','/') THEN

          //Do Nothing

      ELSE

//           $(Must_Include=$(vIncludeFile));

          vString = vString & '$'&'(Must_Include=$(vIncludeFile));';

      END IF

NEXT vIncludeFile

$(vString);

CALL SubRoutineFromQVS 

jepeerik
New Contributor III

Re: Sub from Include not found when Call is outside IF-statement

I think I understand your work-around. And that should work indeed.

I'll test this.

Many thanks.

Greetings,

Jörgen

Sharing knowledge increases your knowledge