Qlik Sense documentation and resources.
***UPDATED 06/30/2021
To resolve rest connector related issues visit:
**UPDATED 10/16/2020
Revised Sense Sample to include updated cookie parsing and proper error handling
Added sample to trigger an NPrinting User Import Task from Qlik Sense
****
One of the most common questions is how can i distribute my NPrinting reports to occur automatically as soon as my Qlik app is done reloading ?
THis is possible in both Qlik Sense and with QlikView using the NPrinting API. Moreover, you can invoke the API through the the Qlik load script Qlik REST Connector v1.3+. What this means is that you can schedule and/or chain your NPrinting report distributions using the Qlik Sense scheduler or the QlikView publisher to better integrate the operations across the platform
.The sample included herein draws on the great document published by gianluca perrin on Qlik Community here: https://community.qlik.com/thread/292037
Benefits
Should the NPrinting task, publisher has a built in solution to notify administrators. Qlik Sense also has 3rd party solutions to do the same.
Restrictions
You need to have v1.3 of the Qlik REST Connector. Its available as of Feb 2018.
Sample
Connection setup
You will need to create two REST Connector connections to the NPrinting API. One that uses a default HTTP method of "GET" , the other will use "POST" as the default method.
Please reference pages 8-9 of the document https://community.qlik.com/thread/292037 to create the two connections.
App Setup
1. Import the attached application and open the script in the Data Load Editor
2. Modify the SETUP tab to reflect your
i. on lines 25/26 update the names of the two REST Connections that you create using the steps in 'Connection Setup' above.
ii. on line 30 , if NPrinting is configured to use https (it is by default) leave this setting to 'Yes' . If you reconfigured it to use http , set to 'No'
iii. On line 31 , set the NPrinting server and endpoint (host + port)
iv: Line 35 is the name of the NPrinting Publish Task that you want to execute
v: Line 37 and 38 is an enhancement to have Qlik check the NPrinting task executions for errors, or , if it runs too long, to abort it and report a failure .
3. (optional) You can also Import the following application into Qlik Sense to send an administrative alert. THis is not necessary with QV Publisher as it has an in-built feature to notify administrators when a publish task fails.
4. Open the imported app in the data load editor and update the 'setup' section
i. on lines 21/22 update the names of the two REST Connections that you create using the steps in 'Connection Setup' above.
ii. on line 26 , if NPrinting is configured to use https (it is by default) leave this setting to 'Yes' . If you reconfigured it to use http , set to 'No'
iii. On line 37 , set the NPrinting server and endpoint (host + port)
iv: Line 32 is the name of the NPrinting Publish Task that will alert an administrator about a report failure
(note that i've toyed with using the Notification Web Connector to send an administrative email alert in the event of a full blown NPrinting outage. This sample is a little simpler)
Task setup
In Qlik Sense QMC under tasks i've setup 3 tasks .
Task #1 - reloads a Qlik App
Task #2 - Distributes reports in an NPrinting Publish task (this is chained to execute 'on success' of Task #1)
Task #3 - Send an Administrator alert (this is chained to execute 'on failure' of Task #2)
QLIKVIEW
The QLikVIew solution has all the same benefits as the Qlik Sense solution with a couple more benefits.
Additional benefits:
- you can pass the vTask name from the publisher task to make for greater re-usability of the load script for chaining multiple tasks
- Publisher has a built in admin notification feature. SHould the NP task fail, the publisher task will also fail and an admin notification will be sent (you can do that with qlik sense but need to use a 3rd party qlik sense task notification solution, or use the load script to call an administrative task to send a notification. The latter can be done with NPrinting or with the Qlik Web Notification Connector.
Load script
The QlikView load script has a login , get task ID (lookup using task name), post task execution, and a task execution check tab. The task execution check tab will monitor the NP task execution on an interval with a configurable timeout. Should the NP task throw a warning or error, it errors out the publisher task. Should the NP task exceed the timeout, it kills the NP task and errors out the publisher task.
You will need to update the NPServer, Task and timeout settings in the CONFIG tab. Again use the REST Connector 1.3 and i suggest testing with QV desktop first . The REST Connector must be manually installed on QV desktop and on the publisher machine to work.
New cookie parsing:
//Set Cookie header
let vCookieRaw = peek( 'Set-Cookie',0,'_response_header');
if vSSL='False' then
let vCookie= subfield(subfield('$(vCookieRaw)','Path=/,',3),';',1);
else
// let vCookie = TextBetween('$(vCookieRaw)','Secure,','Path=/',2);
Let vCookie = TextBetween('$(vCookieRaw)','SameSite=None,','; Path=/',3);
end if
Related information:
Everything works now except it does not trigger NPrinting publish task.
Very similar to what @Mingsum214 described just I use Qlik Sense.
I run the script with the debugger on and all looks good, getting the id of the publish task based on name, creating the vEndpoint, cookies etc) just fPostTaskExecution does nothing on the NPrinting side. No task is triggered, so no executed task id etc.. . this table RestNPTaskTriggerTable does not return any records.
Share your Qlik Sense script log as well as the NPrinting Web Engine log + NPrinting Scheduler log. I'll see if I can find anything
While reading other articles (over and over), making changes here and there in QS and NP it worked.
Thank you for your help.
Hello @JonnyPoole ,
Thank you so much for this post, this was something I've been looking for a very long time.
I have managed to implement your script but sometimes I am getting very random outcomes (I am running the script on PROD for a few months).
In QMC tasks mostly end up as failed even though they successfully finish in NPT. The task log for the failed tasks is the same for all and ends up on these lines:
20220726T083406.237+0200 0028 LIB CONNECT TO 'NPTAPIGET (admin)'
20220726T083407.559+0200 Connected.
20220726T083407.564+0200 0030 RestConnectorMasterTable:
20220726T083407.565+0200 0031 SQL SELECT
20220726T083407.565+0200 0032 "__KEY_data",
20220726T083407.565+0200 0033 (SELECT
20220726T083407.565+0200 0034 "id",
20220726T083407.565+0200 0035
20220726T083407.565+0200 0036 "name",
20220726T083407.565+0200 0037 "__FK_items"
20220726T083407.565+0200 0038 FROM "items" FK "__FK_items")
20220726T083407.565+0200 0039 FROM JSON (wrap off) "data" PK "__KEY_data"
20220726T083407.565+0200 0040 with Connection (
20220726T083407.565+0200 0041 URL "https://czgh01snprint.praha.cz:4993/api/v1/tasks",
20220726T083407.565+0200 0042 HTTPHEADER "Cookie" "NPWEBCONSOLE_SESSION=4c883ba7a46a5b4d265a034ac9afe0af61db288d-%00userid%3A3c072167f6d747c584157219edd972e1%00%00userlogin%3A2022-07-26T06%3A34%3A04.9534982Z%00%00NPWEBCONSOLE_XSRF-TOKEN%3ASq5v3iAYWWk7M3z3dnqBT0ZA0noRK%2BboMZrDY1HsZVQ%3D%00%00_TS%3Asession%00",
20220726T083407.565+0200 0043 QUERY "Limit" "1000000"
20220726T083407.565+0200 0044 )
20220726T083408.316+0200 General Script Error in statement handling
20220726T083408.316+0200 Execution Failed
20220726T083408.332+0200 Execution finished.
The script doesn't even check for the NPT task status. It just triggers the publish and fails. But also sometimes it works as intended and sometimes it doesn't trigger the NPT task at all.
Would you happen to have any idea why it sort of has a mind of its own?
Hi - send me your QVF file and I'll review the script for errors / logic issues