Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

possible to use tloop with dynamically changed variable for condition

Hi, I am doing a development, which requires to run mulitiple time of a job. I am thinking to use tloop with While clause. However, the requirement is the condition is coming from a variable, which may be changed. I am wondering how to use the condition in tloop while clause. Also I am wondering how to pass a variable to the sql in tPostgresInput.
Thanks,
Labels (2)
12 Replies
Anonymous
Not applicable
Author

Hi
You might use tContextLoad and load it into a context variable.
For more information, please download the document here and get scenarios about this component.
Regards,
Pedro
Anonymous
Not applicable
Author

Can the condition in tLoop take the conext varaible?
Anonymous
Not applicable
Author

Hi
Yes. Of couse.
Let's say we have added a context variable called context.new1.
You can type it as the following image.
Regards,
Pedro
Anonymous
Not applicable
Author

Hi
you suggested of using tContextLoad, which can load the properties of dbinput. I know how to make it works. My question is to enter variables in the Query, such as:
Select a.id
, a.registration
from comprehensive a
where a.registration_time between (context.time1) and (context.time2).
I would to know how to assign time1 and time2.
Thanks,
Anonymous
Not applicable
Author

Hi
"Select a.id
, a.registration
from comprehensive a
where a.registration_time between "+context.time1+" and "+context.time2

Regards,
Pedro
Anonymous
Not applicable
Author

Thanks a lot. It all works.
Anonymous
Not applicable
Author

Hi pedro,
I have got the sql that using context variables working. But when I tried to use context in tLoop with the context variable assigned to a while loop condition. I got the Exception in component tLoop_1
java.lang.NullPointerException.
I am using:
dbInput->tMap->tContextLoad--(onComponentOk)-->tLoop->tSleep.
I am using key: run_num, value:2 in the tContextLoad. In tLoop, i am using "i<context.run_num" as the condition.
I tried the same assignment with FileList. it works. I don't know why the above one doesn't work.
Any help is very apprecaited.
Thanks,
Anonymous
Not applicable
Author

Hi
Please show me the entire error log.
Maybe the value didn't pass into context vairable by using tContextLoad.
You'd better check it.
Regards,
Pedro
Anonymous
Not applicable
Author

thanks for the quick reply. I found the error. It's a bug in my code. Thanks again.