Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
We have an app that runs in Qlik Sense to trigger NPrinting task, which is chained to a main app, meaning once the main app runs finish, this NPrinting trigger API task will then run to trigger the NPrinting tasks. We have been experiencing frequent failures of the NPrinting Trigger Tasks recently. This works well most of the time but once it fails, the NPrinting task has to be recreated.
-Retrieved 0 rows when retrieving task_name from NPrinting tasks
Recreating the task in NPrinting resolved the problem. However, the same issue has continued to occur intermittently on other tasks, and this workaround is not a sustainable solution for us.
QS Script as below:
vURL is being maintained in excel.
LIB CONNECT TO 'NPrinting Rest Login (GET)';
RestConnectorMasterTable:
SQL SELECT
"Set-Cookie",
"__KEY__response_header"
FROM JSON "_response_header" PK "__KEY__response_header";
Let vCookieRaw = Peek('Set-Cookie',0,'cookie_items');
Let vCookie = TextBetween(
vCookieRaw,
'SameSite=None,',
' Path=/',
SubStringCount(vCookieRaw,'SameSite=None')-1
);
LIB CONNECT TO 'NPrinting Rest Login (GET)';
RestNPTasksMasterTable:
SQL SELECT
"__KEY_data",
(SELECT
"id",
"name",
"enabled",
"__FK_items"
FROM "items" FK "__FK_items")
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION(
URL "$(vURL_1)",
HTTPHEADER "cookie" "$(vCookie)"
);
TRACE **$(vURL_1) **;
[task_items]:
LOAD
[id] AS [tasks_taskId],
[name] AS [tasks_taskName]
RESIDENT RestNPTasksMasterTable
WHERE NOT IsNull([__FK_items])
//AND [enabled] = 'True'
AND [name] = 'Sales Report - 01';
LET vTaskCount = NoOfRows('task_items');
IF $(vTaskCount) = 0 THEN
TRACE *** ERROR: NPrinting task not found! ***;
EXIT SCRIPT 1;
ENDIF;
DROP TABLE RestNPTasksMasterTable;
LET vNumberTasks = NoOfRows('task_items');
FOR i = 0 TO vNumberTasks - 1
LET vTaskId = Peek('tasks_taskId', i, 'task_items');
LET vTaskName = Peek('tasks_taskName', i, 'task_items');
TRACE Triggering NPrinting Task: $(vTaskName);
LET vPublishURL =
'$(vURL_1)' &
'$(vTaskId)' &
'/executions';
// REST Connection (POST)
LIB CONNECT TO 'NPrinting Rest Connection (POST)';
RestNPTaskTriggerTable:
SQL SELECT "__KEY_data"
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION(
URL "$(vPublishURL)",
HTTPHEADER "cookie" "$(vCookie)"
);
DROP TABLE RestNPTaskTriggerTable;
NEXT
Drop Table [task_items];
Sleep(180000);
LIB CONNECT TO 'NPrinting Rest Login (GET)';
RestConnectorMasterTable:
SQL SELECT
"Set-Cookie",
"__KEY__response_header"
FROM JSON "_response_header" PK "__KEY__response_header";
Let vCookieRaw = Peek('Set-Cookie',0,'cookie_items');
Let vCookie = TextBetween(
vCookieRaw,
'SameSite=None,',
' Path=/',
SubStringCount(vCookieRaw,'SameSite=None')-1
);
LIB CONNECT TO 'NPrinting Rest Login (GET)';
RestNPTasksMasterTable:
SQL SELECT
"__KEY_data",
(SELECT
"id",
"name",
"enabled",
"__FK_items"
FROM "items" FK "__FK_items")
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION(
URL "$(vURL_1)",
HTTPHEADER "cookie" "$(vCookie)"
);
TRACE **$(vURL_1) **;
[task_items]:
LOAD
[id] AS [tasks_taskId],
[name] AS [tasks_taskName]
RESIDENT RestNPTasksMasterTable
WHERE NOT IsNull([__FK_items])
//AND [enabled] = 'True'
AND [name] = 'Sales Report - 02';
LET vTaskCount = NoOfRows('task_items');
IF $(vTaskCount) = 0 THEN
TRACE *** ERROR: NPrinting task not found! ***;
EXIT SCRIPT 1;
ENDIF;
DROP TABLE RestNPTasksMasterTable;
LET vNumberTasks = NoOfRows('task_items');
FOR i = 0 TO vNumberTasks - 1
LET vTaskId = Peek('tasks_taskId', i, 'task_items');
LET vTaskName = Peek('tasks_taskName', i, 'task_items');
TRACE Triggering NPrinting Task: $(vTaskName);
LET vPublishURL =
'$(vURL_1)' &
'$(vTaskId)' &
'/executions';
// REST Connection (POST)
LIB CONNECT TO 'NPrinting Rest Connection (POST)';
RestNPTaskTriggerTable:
SQL SELECT "__KEY_data"
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION(
URL "$(vPublishURL)",
HTTPHEADER "cookie" "$(vCookie)"
);
DROP TABLE RestNPTaskTriggerTable;
NEXT
Seeking advise from API experts.
Best Regards,
Nelson
Please let me know if you have the solution too
Hi @NelsonOng
first thing you need to do is to remove/comment out “where” statement which filters tasks by name and exit script at that point to preview if you are getting any tasks.
also i dont see in your script if you are filtering those by app and i dont see query limit which means you only getting like top 50 tasks only.
In my library from nprintingadventures blog there is query limit implemented and set to 1000 or similar. Make sure your value is big enough to bring in all tasks you have in nprinting.
cheers
Hi @Lech_Miszkiewicz ,
Thanks for reaching out. But afraid that's not the issue. The WHERE clause works well and only loads the task name we want. Since we want to tag each NPrinting trigger task to a main app to run the trigger after a main app finish reloading in Qlik Sense.
Long story short: this script runs well. But will receive NoOfRows for field task_name=0 after some weeks?
Best Regards,
Nelson
HI @NelsonOng
apologies, I read through all comments again and I actually think problem is different and it may have something to do just with your environment or maybe we dont have enough information. Lets assume scenario:
We need to understand what is going on in your enviornment to know what can cause this issue
Here are your answer,
1. technically few minutes, depending on how many tasks i want to trigger in NPrinting.
2.yes, it works like a normal trigger task
3.yup, still able to manual run from NPrinting task execution
4.nothing is run, cause QS script get 0no of rows for task_name, hence it throws an error straight (script is built up that way)
5.high specs QS & NPrinting, multinode environment & dedicated for NPrinting
6. no... but it wont hit max when generating report.
7.yep, not sure if it's an NPrinting bug or REST API connector bug. or probably due to how the cookie is obtained then handled.
8.~20-30tasks
9.No tasks parallel, i used sleep() function in the QS trigger task script to ensure they don't run parallely & consume max resources of the server
10. qs-may 25, np-feb 25
11.yep, dedicated nodes on multinode environment + NPrinting own server
12. yep!
Best Regards,
Nelson