Skip to main content
Announcements
Defect acknowledgement with Nprinting Engine May 2022 SR2, please READ HERE
cancel
Showing results for 
Search instead for 
Did you mean: 
mikaelsc
Specialist
Specialist

delay nprinting triggered task

Hello, 

is it possible to delay the execution of triggered nprinting tasks (through api).

 

the situation is that i have a qlik app that reloads and ends by triggering an nprinting task https://help.qlik.com/en-US/nprinting/May2022/APIs/NP+API/index.html?page=57

the "problem" is that the nprinting task starts generating the report sometimes before the app is saved... resulting in a report containing "old" data on some sheets, and "refreshed" data on the next sheets. 

 

@Lech_Miszkiewicz Qlik NPrinting 

Labels (2)
1 Solution

Accepted Solutions
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @mikaelsc 

"i'm triggering the api call from the same app" - that will never work properly! 

Yes you need to create individual apps and it may add more apps and tasks but it does not get too messy as long as you have streams and app names created with NPrinting in mind and you keep naming convention in place.

cheers

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.

View solution in original post

6 Replies
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

Sure @mikaelsc 

I am assuming you are triggering that API call via another Qlik App script. Why dont you put in your API script SLEEP  XXXX statement so script waits some time before executing any further statements:

https://help.qlik.com/en-US/sense/February2024/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegu...

cheers

Lech

 

 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
mikaelsc
Specialist
Specialist
Author

hello. 

that's what i feared... i'm triggering the api call from the same app.

(i think if i have to create a second "api_trigger" app for each app i want to use the api trigger stuff it will get very messy...) 

 

thanks 😉 

Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @mikaelsc 

"i'm triggering the api call from the same app" - that will never work properly! 

Yes you need to create individual apps and it may add more apps and tasks but it does not get too messy as long as you have streams and app names created with NPrinting in mind and you keep naming convention in place.

cheers

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
mikaelsc
Specialist
Specialist
Author

thanks !

mikaelsc
Specialist
Specialist
Author

i couldn't let this go ;-)... 

i ended up replacing the "call" api logic in each qlik sense app by a statement storing a qvd with the name of the nprinting task to trigger: 

 
trigger: 
load 
timestamp(now()) as triggerTS
AutoGenerate(1); 
 
store trigger into "lib://QVD_Source/000_NPrinting_Triggers/NPRINTINGTASKID.qvd" (qvd); 
drop table trigger; 
 
then instead of 1 "trigger" app per base app, there is one trigger app picking up the info in the qvds, 
then triggering the tasks that haven't been triggered since the last reload: 
 
 
IF FileSize('lib://QVD_Source/000_NPrinting_Triggers/00_LastReload/00_LastReload.qvd')>0 THEN
let vLastReload = num((FileTime('lib://QVD_Source/000_NPrinting_Triggers/00_LastReload/00_LastReload.qvd')));
 
trace existing last reload;
trace $(vLastReload); 
 
ELSE 
 
let vLastReload = num(timestamp(now()-1/24));
trace  no existing last reload;
 
ENDIF; 
 
"00_LastReload": 
load 
timestamp(now()) as _lastTriggered
AutoGenerate(1); 
 
store "00_LastReload" into "lib://QVD_Source/000_NPrinting_Triggers/00_LastReload/00_LastReload.qvd" (qvd); 
drop table "00_LastReload";
 
Triggers: 
LOAD
    triggerTS,
    timestamp('$(vLastReload)') as lastReload,
    FileBaseName() as triggerNprintingTask,
    if(FileTime()>'$(vLastReload)',1,0)as trigger_recent
FROM [lib://QVD_Source/000_NPrinting_Triggers/*.qvd]
(qvd);
 
inner join(Triggers) 
load 
1 as trigger_recent
AutoGenerate(1); 
 
for i = 0 to NoOfRows('Triggers')-1
 
let vTriggerTask = peek('triggerNprintingTask',$(i),'Triggers');
call startNPrintingTaskAZSM('$(vTriggerTask)');
 
next i 
exit script; 
 
this trigger app is scheduled to run quite frequently... to result in something being "near real time". 
 
 
 
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @mikaelsc

This is very good as long as you are happy with this approach and it works for you. I can see what you do and frankly I have similar solution with one of my clients. The only thing I dont like about this approach is troubleshooting if something didnt run for some reason. You have to go through the logs and find out what/when didn't run...

I was contemplating the idea of having "live"  register  of tasks in form of QVD which in fact could be just single file with typical attributes like:

App Name Task Name Created Triggered Trigger flag
a a 08/03/2024 12:12 08/03/2024 12:15 1
a a 08/03/2024 13:12 08/03/2024 13:15 1
a a 08/03/2024 14:12 08/03/2024 14:15 1
a a 08/03/2024 15:12    

 

Similar to your approach instead of creating QVD with task name I would just concatenate to above table 1 line with the app name and task name to put it in the queue.

Then API trigger app would loop through the empty trigger tasks and woud update so you could see when it was run and at the same time such task would be marked as completed. You could have that table shown on UI of your API app to have full register which you can easily adit. Lastly that way you could actually have reload of this app set as a trigger from another app making it always "real time" and as long as there is a record in it it will be picked up and executed.

cheers 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.