Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
Make your voice heard! Participate in the 2020 Wisdom of Crowds® Survey. BEGIN SURVEY
Highlighted
Not applicable

OnPostReload macro create PDF does not work

Hi All

I have a macro to print pdf's with a trigger OnPostReload that works ok when the QlikView document is reloaded directly via the desktop but when my document is reloaded via the server it does not create the pdf?. Does anyone have any ideas or suggestions. Using 9 sr5, QlikViewPDF, have set Requested Module Security to System Access and Current Local Security to Allow System Access.

'***************************************************

'Functions creates the reports in PDF format

'***************************************************

sub CreateReports

"D:\DataPDF"

"RP01"

set rep = ActiveDocument.GetReport(reportID)

set vShow = ActiveDocument.Variables("vShow")

"on", true

'Create the file name with path

"" & reportID & "_" & reportName & ".pdf"

'print the report

'Call the function

'Rename the report

'checkOutputFile reportFile, tempFolder 'Call the function

'call ClearDefault() 'Call the function

end sub

'***************************************************

'Actual function to print the PDF format without being asked for location to save

'***************************************************

function printReportPDF(oReport, pdfLocation)

Set WSHShell = CreateObject("WScript.Shell")

"HKCU\Software\CUSTPDF Writer\DefaultLocation", pdfLocation, "REG_SZ"

"HKCU\Software\CUSTPDF Writer\UseJobName", "1", "REG_SZ"

"HKCU\Software\CUSTPDF Writer\UseDefaultLocation", "1", "REG_SZ"

'QV Print

"QlikViewPDF",false

set WSHShell = nothing

end function

Many thanks

Steve.

1 Solution

Accepted Solutions
Highlighted
Not applicable

OnPostReload macro create PDF does not work

Hi Miguel

Thank you very much. I had spent hours trying different things. What you gave me was exactly what I needed. If QlikView don't already pay you a salary they should J

You are very knowledgeable and very helpful. Many thanks

For anyone else out there this is how I got around macro's not working through publisher - through OnPostReload

My full task was to create PDF's on a daily basis with a sales summary.

I created a hidden sheet with a qv variable vshow so that the sheets would not be visible by the users, and I could create custom objects for the report

I created a report in my QlikView document using the objects from the hidden sheet

I created the following macro in the qv document

'***************************************************

'Functions checks if the report should be run

'***************************************************

sub ReportCheck

set var = ActiveDocument.Variables("vCreatePDF")

val = var.GetContent.String

if val = 1 then

call CreateReports

var.SetContent 0, true

end if

End Sub

'***************************************************

'Functions creates the reports in PDF format

'***************************************************

sub CreateReports

tempFolder = "D:\DataPDF"

reportID = "RP01"

set rep = ActiveDocument.GetReport(reportID)

'set vShow = ActiveDocument.Variables("vShow")

'vShow.SetContent "on", true

reportName = rep.Name

'Create the file name with path

reportFile = tempFolder & "\" & reportID & "_" & reportName & ".pdf"

'print the report

printReportPDF reportID, tempFolder 'Call the function

'Rename the report

'checkOutputFile reportFile, tempFolder 'Call the function

'call ClearDefault() 'Call the function

end sub

'***************************************************

'Actual function to print the PDF format without being asked for location to save

'***************************************************

function printReportPDF(oReport, pdfLocation)

Set WSHShell = CreateObject("WScript.Shell")

WSHShell.RegWrite "HKCU\Software\CUSTPDF Writer\DefaultLocation", pdfLocation, "REG_SZ"

WSHShell.RegWrite "HKCU\Software\CUSTPDF Writer\UseJobName", "1", "REG_SZ"

WSHShell.RegWrite "HKCU\Software\CUSTPDF Writer\UseDefaultLocation", "1", "REG_SZ"

'QV Print

ActiveDocument.PrintReport oReport, "PDFCreator",false

set WSHShell = nothing

end function

I created a trigger OnOpen to run macro "ReportCheck"

I created the a second qv document to distribute or create my pdf through a schedule

execute "C:\Program Files\QlikView\Qv.exe" /R /vvCreatePDF=1 /NoSecurity "D:\QVApps\Dev\Sales\EMEA V3.08.qvw"

I run my main qv on a daily schedule through publisher then i run the second qv loading on completion of the first to generate the PDF's

I then use a program blat and windows schedule to attach my PDF's to emails and send to recipients.

Hope this helps other people out to... Thanks to everyone.

View solution in original post

22 Replies
Highlighted

OnPostReload macro create PDF does not work

Hello Steve,

First, have you checked you are allowing macro execution on server in QlikView Management Console / User Documents?

Second, Do you have the report available when you open the document in server?

And last, do you have a "CUSTPDF Writer" printer in your server?

They may be obvious, but they are the main things that may differ from your computer to the server.

Regards.

Highlighted
Not applicable

OnPostReload macro create PDF does not work

Hi Miguel

When I run the QlikView document (Reload) I am actually running it on the server, and it generate the PDF from the OnPostReload trigger, it is only when I use the QlikView Management Console to reload it that it does not trigger the OnPostReload trigger to create the PDF. Please see below in answer to the info you sent.

First, have you checked you are allowing macro execution on server in QlikView Management Console / User Documents? - In QlikView Management Console / QlikView Server Settings / Security - the option Allow Macro Execution on Server - is enabled

Second, Do you have the report available when you open the document in server? Yes the report is available to use and the auto pdf of the report does work. (FYI I develop on the server itself)

And last, do you have a "CUSTPDF Writer" printer in your server? I use PDF-Xchange 3.0

Highlighted
Not applicable

OnPostReload macro create PDF does not work

Macros cant be run like that, see:

http://community.qlik.com/forums/t/26240.aspx

Highlighted
Not applicable

OnPostReload macro create PDF does not work

Hi Danjo

Thanks for your input. Setup a batch with


D:\QVApps\Dev\Sales>"C:\Program Files\QlikView\Qv.exe" /R "D:\QVApps\Dev\SalesEMEAV3.08.qvw"


It opens a window - executes the file (I see the Script execution Progress window come up and run through the qvw file) - but still does not run the OnPostReload trigger to run the macro CreateReports

It also does not close the window when it is finished?

Any ideas?

Regards Steve

Highlighted
Not applicable

OnPostReload macro create PDF does not work

You need to run it twice using the Publisher since the trigger for OnPost Reload does not work when uploads are being done using the Publisher. OnOpen triggers do work in the Publisher.

Each time that you run the upload, you need to pass a parameter that will be use by the OnOpen trigger macro. The first upload's parm will be used in the macro to bypass the PDF cycle and just do the upload of the QV. The second time the QV is is opened for upload, the parm will indicate to the macro to go ahead and run the PDG generation. At the end of the macro, it should save the QV and quit the QV.

1st upload: (content of vPDF = NO)

n:\\\qv.exe /r /vPDF n:\dircrectory\document.qvw

2nd upload (content of vPDF = YES)

n:\\\qv.exe /l vPDF n:\dircrectory\document.qvw

You will probably need to put the above statements in a cmd file to be executed by "External Programs" in the Publisher.

and the statement in the "External Programs" should be something like this:

C:\WINDOWS\system32\CMD.exe /c n:\Qlik\Execution_Batch_Files\Generate PDF.cmd

Highlighted
Not applicable

OnPostReload macro create PDF does not work

Hi Fredrick

Many thanks, I have been trying to create the macro, but I can not seem to get it to work. Any idea as to why? It will not run the CreateReports or set the vPDF to 0.

sub ReportCheck
if vCreatePDF = 1 then
CreateReports
set vPDF = ActiveDocument.Variables("vCreatePDF")
vPDF.SetContent "0",true
end if
End sub

Highlighted

OnPostReload macro create PDF does not work

Hello Steve,

You need first to get the value from the variable, (my guess is that vCreatePDF is not a macro variable but a QlikView variable):

Sub ReportCheck set var = ActiveDocument.Variables("vCreatePDF") val = var.GetContent.String if val = 1 then call CreateReports var.SetContent 0, true end ifEnd Sub


Hope that helps

Highlighted
Not applicable

OnPostReload macro create PDF does not work

Hi Miguel

Thank you very much. I had spent hours trying different things. What you gave me was exactly what I needed. If QlikView don't already pay you a salary they should J

You are very knowledgeable and very helpful. Many thanks

For anyone else out there this is how I got around macro's not working through publisher - through OnPostReload

My full task was to create PDF's on a daily basis with a sales summary.

I created a hidden sheet with a qv variable vshow so that the sheets would not be visible by the users, and I could create custom objects for the report

I created a report in my QlikView document using the objects from the hidden sheet

I created the following macro in the qv document

'***************************************************

'Functions checks if the report should be run

'***************************************************

sub ReportCheck

set var = ActiveDocument.Variables("vCreatePDF")

val = var.GetContent.String

if val = 1 then

call CreateReports

var.SetContent 0, true

end if

End Sub

'***************************************************

'Functions creates the reports in PDF format

'***************************************************

sub CreateReports

tempFolder = "D:\DataPDF"

reportID = "RP01"

set rep = ActiveDocument.GetReport(reportID)

'set vShow = ActiveDocument.Variables("vShow")

'vShow.SetContent "on", true

reportName = rep.Name

'Create the file name with path

reportFile = tempFolder & "\" & reportID & "_" & reportName & ".pdf"

'print the report

printReportPDF reportID, tempFolder 'Call the function

'Rename the report

'checkOutputFile reportFile, tempFolder 'Call the function

'call ClearDefault() 'Call the function

end sub

'***************************************************

'Actual function to print the PDF format without being asked for location to save

'***************************************************

function printReportPDF(oReport, pdfLocation)

Set WSHShell = CreateObject("WScript.Shell")

WSHShell.RegWrite "HKCU\Software\CUSTPDF Writer\DefaultLocation", pdfLocation, "REG_SZ"

WSHShell.RegWrite "HKCU\Software\CUSTPDF Writer\UseJobName", "1", "REG_SZ"

WSHShell.RegWrite "HKCU\Software\CUSTPDF Writer\UseDefaultLocation", "1", "REG_SZ"

'QV Print

ActiveDocument.PrintReport oReport, "PDFCreator",false

set WSHShell = nothing

end function

I created a trigger OnOpen to run macro "ReportCheck"

I created the a second qv document to distribute or create my pdf through a schedule

execute "C:\Program Files\QlikView\Qv.exe" /R /vvCreatePDF=1 /NoSecurity "D:\QVApps\Dev\Sales\EMEA V3.08.qvw"

I run my main qv on a daily schedule through publisher then i run the second qv loading on completion of the first to generate the PDF's

I then use a program blat and windows schedule to attach my PDF's to emails and send to recipients.

Hope this helps other people out to... Thanks to everyone.

View solution in original post

Highlighted
Not applicable

OnPostReload macro create PDF does not work

This might be a dumb question, but if I'm running the /R command from the command line, do I need QlikView Desktop installed on my server? I have Publisher installed on the server, I dont think there's a QV Desktop on it at the moment.