Monday, August 26, 2013

QlikView "Execute" can save your butt!

I ran into an issue the other day. I wanted to pull some data from a site and the data was stored in multiple xml files within a zip file.

This presented two problems for me as a QlikView Developer. How do I get the zip file down to my computer? Then how do I unzip the files so QlikView can read them?

Qlikview's "Execute" command makes this all possible.
You do have to enable execution of external programs in your load script but otherwise it is just another line of code.


The zip file was found at http://somedomain/somezip.zip so in order to download it I had to use a powershell command luckily the windows command line will execute powershell commands.

Disclaimer: I DON'T KNOW ANYTHING about powershell so be advised, comments on this post asking how to do stuff in powershell will be met with crickets. I'm sure there is great stuff in there and I'll figure those things out when I need them. I did some googling to figure out how to download the file from the command line so this line of code is all I know about powershell.

execute cmd.exe /C powershell (New-Object System.Net.WebClient).DownloadFile('http://somedomain.com/somezip.zip','C:\Test\somezip.zip');

So that line of code downloads the zip file from the web site and stages it in c:\Test. The next challenge is unzipping it. You may be able to extract the contents of a zip file from windows explorer but there is way to do it from the command line without downloading an executable that you can call. I got mine from http://stahlworks.com/dev/?tool=zipunzip download at your own risk. Once I downloaded the file I placed it in C:\Windows\System32. From there I could call it from my Qlikview load script using the Execute command.


execute cmd.exe /C unzip -o C:\Test\somezip.zip -d C:\Test;

This was just one way I am using the Execute command but there are many ways you can use it. For example you may want to copy data files to another directory after you load them. There are almost unlimited things you can do from the command line so keep it in mind when you are trying to solve a tricky problem.

3 comments:

  1. Good to see you blogging again, nice tip!

    I often use the execute statement like in your second example, to move processed files into an archive directory so that they're not reprocessed each time. Regarding command line unzipping, I would recommend 7-Zip (also for 'regular' UI unzipping): http://www.7-zip.org/

    ReplyDelete
  2. Thanks Barry,

    There were several options for unzip, I really only needed one I could access from the command line since windows we meeting my needs.

    Thanks

    Chris

    ReplyDelete
  3. Thanks for great information about Qlikview, you write it very clean. I am very lucky to find your blog & get an useful info tips from you. thanks a lot. QlikView Training in Hyderabad

    ReplyDelete