QlikView – Open, Save, Close a QVW without reloading data using PowerShell


So you can open a QVW file from the command line with one of the following options

/r Reload, save, close.
/rp Partial-Reload, save, close.
/l Reload, leave open.
/p Partial-Reload, leave open.
/v Pass variable.

None of these options suited me, what I wanted was the following; Open QVW, immediately save it without doing anything i.e. not reloading data, not open script, nothing… then close the file. I was pointed towards the Automation Documentation over here http://community.qlikview.com/docs/DOC-1793 and I was provided with a macro that uses the COM Object in one QVW that opens, saves and closes another QVW. This solved the problem and could be called from the command line.

I didn’t like this solution as it was a bit hacky… Having one file call another etc etc, and I use PowerShell for the rest of my automation; I figured there has to be a PowerShell solution and came up with the following script:

function qv-SaveAndClose-QVW
{
 param(
  [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
  $QvwPath
 )
 $qvComObject = new-object -comobject QlikTech.QlikView
 $NewDoc = $qvComObject.OpenDoc("$QvwPath")
 $NewDoc.Activate()
 $NewDoc.Save()
 $NewDoc.CloseDoc()
 $qvComObject.Quit()
}
Advertisements

4 thoughts on “QlikView – Open, Save, Close a QVW without reloading data using PowerShell

  1. Hi there. Great idea. We came across the same hurdle. The problem we are getting now is the save. The process stops at a save as and do you want to overwrite. Just wondered how you got around this.

    • I guess we are solving different problems. We have a team of 6 that develop the same application in parallel. Before we do deployments we need to ensure all the latest code has been ‘applied’ to the application. The way we do this is, we get the latest code from (Application-PRJ\*.xml etc) from GIT and then use a series of PS scripts to recreate the QVW from an empty template, then “Open, Save and Close” it and lastly copy it to our destination server where the scheduled tasks takes over and reload them. Let me know if you need more information.

  2. Hi
    We are also running GIT and QlikView, this is our last obsticle (we hope).
    We are trying to run this from Publisher but it will not work. Starting powershell from a cmd file by double clicking it works perfectly but it fails in Publisher. Nothing happens.
    ExecutionPolicy is set to Bypass.
    Any ideas?
    Can you give us the powershell syntax you use?

  3. I’ve been looking for something like this, thanks!

    @Manoj: I had the same problem, but was able to get around it by deleting the file before calling $NewDoc.SaveAs(“$QvwPath”) with the following:


    $NewDoc.Activate()
    # Remove existing file so that we are not prompted to overwrite it
    Remove-Item -Path $QvwPath -Force -ErrorAction SilentlyContinue
    $NewDoc.SaveAs(“$QvwPath”)
    $NewDoc.CloseDoc()

    It’s not ideal, but it seems to work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s