4 Replies Latest reply: Mar 6, 2018 8:58 AM by omar bensalem RSS

    Very WEIRD behaviour of the if...else in Qlik ! (This is not a question)

    omar bensalem

      Hi guys ( mto),

       

      I don't know if u're already aware of this; but I've remarked a very strange behaviour when using if..else in qlik sense script.

      In fact, when the condition is put as follow (in the same LINE):

       

      if $(vFXD1)='NULL' or $(vFXD2)='NULL'or $(vFXM)='NULL' or $(vFXMLen)=0 or $(vFXD1Len)=0 or $(vFXD2Len)=0

       

      Qlik Sense will take all of this into consideration

       

      BUT


      If I separate my condition into different lines:

      if $(vFXD1)='NULL'

      or $(vFXD2)='NULL'

      or $(vFXM)='NULL'

      or $(vFXMLen)=0

      or $(vFXD1Len)=0

      or $(vFXD2Len)=0



      QLIK Sense will ONLY take into consideration the first LINE !!!


      That's so ... weird.. to say the least...!

      Can you please have a look at this?


        • Re: Very WEIRD behaviour of the if...else in Qlik ! (This is not a question)
          Petter Skjolden

          It is fully documented that it behaves in this way, the red formatting of the text is mine:

           

          Since the if..then statement is a control statement and as such is ended with either a semicolon or end-of-line, each of its four possible clauses (if..then, elseif..then, else and end if) must not cross a line boundary.


          It is quoted from the documentation here:


          https://help.qlik.com/en-US/sense/February2018/Subsystems/Hub/Content/Scripting/ScriptControlStatements/If.htm


           



            • Re: Very WEIRD behaviour of the if...else in Qlik ! (This is not a question)
              omar bensalem

              Hi again petter-s, stalwar1

              Please assist on this:

               

              I have a simple scenario

              if condition is met then

              call the qlik notification connector (to send email notification);

              exit script;

               

              What I want to do ; if one of the tables are missing, send notification  and exit script:

               

              and in the dashboard, we'll be able to see what tables are missing.

               

              here's what I had (before including the qlik notification connector):

              if $(vFXD1)='NULL' or $(vFXD2)='NULL'or $(vFXM)='NULL' or $(vFXMLen)=0 or $(vFXD1Len)=0 or $(vFXD2Len)=0

               

              THEN

              LET ErrorMode=1;

              exit Script;

               

              This was working FINE; and I can see that the 4 tables are missing !

              Capture.PNG

               

              Now, I altered the script so that I can have only D1 missing..

              and I added the second part (call the notification connector)

               

              if $(vFXD1)='NULL' or $(vFXD2)='NULL'or $(vFXM)='NULL' or $(vFXMLen)=0 or $(vFXD1Len)=0 or $(vFXD2Len)=0 THEN

              LOAD 

              status,

                result, 

              filesattached

              FROM [lib://Notification](qvx);

              LET ErrorMode=1; exit Script;

               

               

              ps: I've tried everyting: the THEN in the same line with the if..

              everything in the same line

              everything in the same line and ; after the then..

               

              but no matter what I do; I'll have only the nofitication email sent; but I won't find the correct missing Dates !! I'll always find that the 4 dates are missing.. which is not true!

              When I elminiate the call of the connector; and rexecute; I'll find the right result !:

              Capture.PNG

              I really am VERY CONFUSED! can you please help me with this? How should I write this condition??

              Thanks !!

                • Re: Very WEIRD behaviour of the if...else in Qlik ! (This is not a question)
                  omar bensalem

                  Let me answer..

                  I'm so confused

                  This works:

                  if $(vFXD1)='NULL' or $(vFXD2)='NULL'or $(vFXM)='NULL' or $(vFXMLen)=0 or $(vFXD1Len)=0 or $(vFXD2Len)=0 THEN

                  LOAD  status,  result,  filesattached FROM [lib://Notification](qvx);

                  //LET ErrorMode=1;

                  exit Script;

                  (ps: then is in the same line of the if condition)

                  When I eliminate the LET ErrorMode=1; it works (the notification is sent and the result in the table are correct)


                  BUT when I eliminate the load  LOAD  status,  result,  filesattached FROM [lib://Notification](qvx); statement,

                  =>

                  if $(vFXD1)='NULL' or $(vFXD2)='NULL'or $(vFXM)='NULL' or $(vFXMLen)=0 or $(vFXD1Len)=0 or $(vFXD2Len)=0 THEN

                  exit Script;

                   

                  The script won't exit ! It will continue unless I add the LET ErrorMode=1;.....


                  Which is reaaaaaally confusing me ! on why it works with one thing to do; but should be eliminated when we'll do 2 things after the "then" key words??


                  And ps:

                  with one condition; then should be placed in a seperate line of the if condition


                  with 2 things (notification + exit)

                  then must be in the same line as the if... if it's not; it won't work..


                  Well, basically, I'm going crazy