How to manage your NPrinting task execution from QlikView script
Recently I have heard this question several times, therefore it might be worth of writting something about it.
Since version 17.2, NPrinting has empowered its features to external programs by its RESTful APIs. User may easilycontrol and get data from the system with the APIs now. It is a very popular scenario that user wants to start the NPrinting Publish task right after the data reload is done in the QlikView application, so that the published report will have the latest data.
There are several possible ways to it. In this example you will find how to trigger and monitor the NPrinting task through QlikView load script, which requires nothing more than a QlikView Desktop and a Qlik REST connector, besides of the NPrinting environment. In the end of this article you will also see how to chain it with a QlikView document reload task in the QMC, so that the NPrinting task will automatically start right after the QlikView reload task is finished.
Some prerequisites for using this example:
Qlik NPrinting June 2017 and later
Qlik REST Connector 1.3
A publish task has been configured correctly with successful report generation in NPrinting (help)
A user has been configured correctly in NPrinting with proper security priviliges, and linked to a Windows Domain user (help)
In order to allow HTTP POST access from QlikView server to NPrinting server, QlikView server’s hostname has been added to the NPrinting Trusted Origins (help)
And this article might be helpful with more information regarding to using NPrinting APIs.
The attached QlikView application in this example is quite self-explanatory. Here I will just list some key components for your attention.
Authentication: First I create a POST request for NTLM authentication (POST/login/ntlm). This is because the later request for triggering the task is a POST request. And Qlik REST connector cannot mix between a GET connection with a POST connection once the connection string is created.
Looping: For polling the task execution status, I use a loop using "Do ... Loop". Pay attention that you want to drop both the master table and data table within one iteration, so the next iteration can get refreshed data value. I use "IF... THEN" to break the loop because I want to keep the last data table so that the user can have some information about the execution left in the data model. I also use a counter to control the loop because I don't want to wait forever during the debug.
The screenshots below show an example of creating a POST connection for authentication in Qlik REST connector.
Download the attached QlikView document and reload it from your QlikView server machine to test how it works.
At last, you may want to create a reload task in QlikView QMC and chain it to the reload task of your data application, so that the NPrinting publish task will be triggered automatically after the QlikView data reload task is completed successfully. You can find the settings from the screenshot below, or get help from this community article.