5 Replies Latest reply: Apr 19, 2017 11:26 AM by luis martin-roldan RSS

    Oddity: peek not working "sometimes"

    luis martin-roldan

      Hi,

       

      I come with a strange situation.

       

      I have an algorithm that makes use of a respectable amount of variables to carefully load information from a data origin and/or its previously loaded data from a past reload (a qvd file).

      In order to reuse this script for a whole set of data origins, since the content of those variables will be unique for each data origin, I thought about making use of a Table containing these values and then doing a for loop, updating the variables content inside the script using the peek function.

       

      In other words: having a table like this

       

      [VariablesContent]:

      vVar1vVar2vVar3...vVarN
      1value11value21value3...1valueN
      2value12value22value3...2valueN
      ...............
      Mvalue1Mvalue2Mvalue3...MValueN

       

      where N would be the number of variables and M the number of data origins.



      And then, in the script, doing a for loop like this (pseudo code)


      for i from 0 to (NoOfRows('VariablesContent') - 1) do

          Let vVar 1 = peek('vVar1', $(i), 'VariablesContent');

          Let vVar2 = peek('vVar2', $(i), 'VariablesContent');

          ...

      next



      Now, I am coming at this little by little. I have only loaded a single row in [VariablesContent] and have started to replace the let expression in these variables with their respective peek('vVarX',0,'VariablesContent') statements, and this actually works... untill the program runs into and If.


      It makes no sense (at least to me), but after entering a branch of the If statement, the peek function will return <NULL> no matter what. Even running the same statements that worked before entering the If will now return <NULL> and it is driving me crazy since I can't figure out what's wrong.


      Can I get some insight, please?

      Thanks in advance,

      Cheers.

        • Re: Oddity: peek not working "sometimes"
          luis martin-roldan

          For now, I have worked around this by executing as many of these variable initializations as possible before running into the If statement; and changing some of the logic where I could not do this.

           

          Still, we may not be as lucky as to be able to pull this through everytime, why do these peek not work?

          • Re: Oddity: peek not working "sometimes"
            Stefan Wühl

            It makes no sense (at least to me), but after entering a branch of the If statement, the peek function will return <NULL> no matter what. Even running the same statements that worked before entering the If will now return <NULL> and it is driving me crazy since I can't figure out what's wrong.

                   

            Which If statement? Are you talking about the FOR loop?

             

            Have you tried to use the script debugger?

             

            If possible, upload a small sample QVW with a sample input file.

              • Re: Oddity: peek not working "sometimes"
                Stefan Wühl

                BTW, I don't think you need the DO in your FOR ... NEXT loop.

                  • Re: Oddity: peek not working "sometimes"
                    luis martin-roldan

                    Thx for replying!

                    BTW, I don't think you need the DO in your FOR ... NEXT loop.

                    I know, that was not QlikSense DataLoadEditor code, just some code to express the idea I had

                     

                    Which If statement? Are you talking about the FOR loop?

                    Inside the algorithm there's a point where the program execution branches depending on a condition, that's what I meant.

                     

                    Have you tried to use the script debugger?

                    I either have little knowledge on how to interpret the output pane or it didn't help much.

                     

                    If possible, upload a small sample QVW with a sample input file.

                    Surely, I uploaded the whole thing (.qvf + data sources).

                    [I'm afraid that the code documentation is written in spanish, I can translate it for you if you need to]

                    [Also, remember to edit the DataConnections so they point to your local directions]

                     

                    Thanks a lot for the help

                    For anything you may need, please feel free to ask.