Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Switch syntax, datasources management

Hello everybody !

I'm a new user for the awesome tool QlikView and i have a few questions about it.

  1. First of all, i'm trying to use the switch syntax but i don't think i really understood how it works.


=if(Country='France','FR',
if(Country='Austria','AUS',
Country))

=switch Country
case 'France'
'FR';
case 'Austria'
'AUS';
default
Country;
end switch

2. Datasources management
I would like to create several QVW files for the publishing part.
For instance, a checkAvailability.qvw, after this a createQVD.qvw...
However, i don't know how i can check the availability of the datasources:

For the files, i've thought about the FileSize function but .... not working ...


LET vFileName = 'file1.txt';
LET vSize = filesize($(vFileName));
if($(vSize)>0,MsgBox('ok'),MsgBox('ko'));

error loading image

I think it's enough for a first post 😉

10 Replies
Not applicable
Author

For the switch statement, a full command must be placed for each case/scenario. Let me edit your code so it becomes more like this...


=switch Country
case 'France'
LER Country = 'FR';
case 'Austria'
LET Country = 'AUS';
default
LET Country = Country;
end switch


in your filesize function, try removing the dollar expansion in your if so it becomes like

if(vSize>0, etc. etc.)


Anonymous
Not applicable
Author

Hi,

For the filesize function, try putting the filename variable in single quotes as it is a string value:

LET vSize = filesize('$(vFileName)');



Not applicable
Author

Thanks rainong, but i don't think its working


=switch Country
case 'FR'
LET Country = 'France';
case 'UK'
LET Country = 'UnitedKinkgdoms';
default
LET Country = Country;

end switch


it displays an empty list box.... 😐

And, for your other answer,


//LET vFileName = 'file1.txt';
LET vSize = filesize('file1.txt');//$(vFileName));
if($(vSize)>0,
MsgBox('ok','cool'),
MsgBox('ko','dead')


it displays another error message

😞

Not applicable
Author

Thanks, JSN, but it displays the same message, but with different values 😉


LET vFileName = 'file1.txt';
LET vSize = filesize('$(vFileName)');
if($(vSize)>0,MsgBox('ok'),MsgBox('ko'));


Anonymous
Not applicable
Author

I see Frank,

it does seem like msgbox is causing the issue since the vSize variable is at least populated.

Try this approach instead:

LET vFileName = 'file1.txt';
LET vSize = filesize('$(vFileName)');
if $(vSize)>0 then
let mbox1=msgbox('ok');
else
let mbox1=msgbox('ko');
end if

Not applicable
Author

Thanks Jsn, it's working !! 😉

Now my next question is do you know how it is possible to "return" a value (for instance, the script didn't finish successfull and i would like to notify the publisher of this...). Moreover,does QV provide a die() function ? Indeed, the aim of this script is to check the availability of the datasources and, if the datasources are OK, it launches the next process (the QVD creation). However, if we want this to be successfull, it means QV and QV Publisher can exchange values...

Thanks Jsn 😄

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

The way to exit a script is with the statement:

exit script;

I believe I saw an earlier post about generating an error exit by conditionally executing a statement that will fail such as:

LOAD * FROM nofile.txt;

You can also use the TRACE script statement to write messages to the logfile.

-Rob

Anonymous
Not applicable
Author

Well,

To stop the script execution you can use the "Exit Script" statement that can also take a when condition.

As for getting several QV reloads to work together, couldn't you use QV Publisher and dependencies? A dependency between two tasks only launches the second task if the first one finished without errors.

Not applicable
Author

I tried to test the script when the file is missing.
QV crashes when i try to get the size of a missing file:


LET vFileName = 'file2.txt';
LET vSize = filesize('$(vFileName)');
if ($(vSize)>0) then
let mbox1=msgbox('ok');
else
let mbox1=msgbox('ko');
end if


Does someone know on which version are QV Publisher dependencies included ? I remember there are two Publisher versions, Standard & Enterprise Editions .

Thanks for your help...

ANd about the switch syntax, can someone help me ? 😉

<pre>=switch Country
case 'FR'
LET Country = 'France';
case 'UK'
LET Country = 'UnitedKinkgdoms';
default
LET Country = Country;

end switch