Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All
I have setup a report with variables, and created a batch file to run the QV document with the variable to output the report in a PDF format. When I run my *.bat file manually it works great. It opens the QV document, send the variable and creates the pdf output. When I schedule the batch file to run through Windows 2008 64bit it just continues to give a state of running in the scheduler, starts a Qv.exe and loads it but never generates the PDF and never closes the Qv.exe.
Does anyone have any suggestions for me. I am stumped. I have spent a few days on this and not sure what to try now.
My *.bat file
call "C:\Program Files\QlikView\Qv.exe" /R /vvCreatePDF=1 /NoSecurity "D:\QVApps\Prod\Sales\EMEA.qvw"
My 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)
reportName = rep.Name
'reportName = "sdkfhjskgh"'Replace(rep.Name," ","_")
'Create the file name with path
reportFile = tempFolder & "" & reportName & " " & Date &".pdf"
'reportFile = 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)
ActiveDocument.PrintReport oReport, "PDFCreator",false
set WSHShell = nothing
end function
'***************************************************
'Checks the output file before renaming the report
'***************************************************
function checkOutputFile(pdfFile,pdfLocation)
Set fileTest = CreateObject("Scripting.FileSystemObject")
'Delete any previous version of the file
if fileTest.FileExists(pdfFile) then
fileTest.DeleteFile pdfFile
End if
'Check if the temp pdf report file has been generated
strTempFile = pdfLocation & "" & "QlikView Printing.pdf"
currentStatus = fileTest.FileExists (strTempFile)
if currentStatus = false then
ActiveDocument.GetApplication.Sleep 10000
checkOutputFile pdfFile,pdfLocation
else
'rename the file
ActiveDocument.GetApplication.Sleep 10000
fileTest.MoveFile strTempFile, pdfFile
end if
set fileTest = nothing
end function
Like I mentioned when I manually run it it works, when I try to run it through Windows task scheduler it does not.
Hi Gordon
My QV server runs on Windows Server 2008, as above the issue is with the Windows Scheduler (Task Scheduler) as the batch files run fine when manually processed. After a few more hours and investigation I managed to succeed
The issue is with QlikView 9 SR4 and Task Scheduler Win2008 service pack 2, I purchased a low cost but great little scheduler (That runs totally independent of MS scheduler) "System Scheduler Professional" from Splinterware ($30) and I can now confirm that the batch files work 100% and I sent out my first batch of automated PDF emails last night.
Thank you to every one for their help.
What is trigger for this macro? OnPostReload?
What you need to do is move this to on "OnOpen" document trigger and make qvw call twice, First time for reload of the document and second time for PDF printing. So your bat s would be like:
"C:\Program Files\QlikView\Qv.exe" /R /NoSecurity "D:\QVApps\Prod\Sales\EMEA.qvw"
"C:\Program Files\QlikView\Qv.exe" /R /vvCreatePDF=1 /NoSecurity "D:\QVApps\Prod\Sales\EMEA.qvw"
Error in .bat file script
Hi Rakesh
This sounds good. I will try your suggestions today and post up how it goes.
Many thanks.
Can you be more precise Sunil?
Are you getting error in batch file? Did you make sure your path are correct? What I would do is put a "PAUSE" command at the end of the batch file and see what the error is.
I wonder if its a permissions things - when you are running it manually its a different profile to that run under the scheduler?
Regards,
Gordon
... in particular where it is deleting any existing PDF ...
No, actually what I have noticed that such heavy macros don't run too good and stable in post reload trigger. Somehow you would feel that they are just skipped some times. May be because QVW is trying to save the document as well after reload, as this symptom is with batch load only.
Hi Rakesh and Gordon
In answer to the questions, I am using a trigger on the Open and not the reload, as could not get that to work. I also then use a email program that uses scheduler to check and when there is a pdf file in the directory it attaches to an email and sends. The email batch also then deletes the pdf, and it uses the same user to run the batch job. (In answer to Gordon's question). I will look to try what Rakesh suggested with the 2 runs this afternoon and hopefully win.
In that case then Rakesh 's solution should sort it out.
I do exactly the same on several documents that use the 'double run' method (first with the /r switch to reload then with a /v to pass a value to a variable to trigger specific events in the OnOpen macro). In the second run the quit method you need is:
ActiveDocument.GetApplication.Quit
Good luck!
Gordon