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

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Set value to Context Variable dynamically

Hi,
i want to set value to Context Variable dynamically and require to use that context variable in number of jobs
say for example:
for example: context.date = date
This variable(context.date) required to use in many jobs, can you please let me know how to implement this.
i have tried below option it works only for corresponding job.


please do the needful.
Labels (2)
8 Replies
Anonymous
Not applicable
Author

Hello kambham
There is a component called tContextLoad which allows you to set context variables dynamically. It enable syou to read values from e.g. a file or DB and load them into the context. The schema which you need to give to tContextLoad is simply 2 strings: "key" and "value". It also allows you to add new variables.
There is also the tContextDump component which allows you to dump the context for review.
Hope this helps.
Anonymous
Not applicable
Author

Hi,
Thanks for your quick response.
As per your email i developed job to read date value from file and load them into the context using tContextLoad, see the below screen shot for your reference and result after executing job.
Starting job tcontext at 12:04 21/04/2016.
connecting to socket on port 3346
connected
tContextLoad_1 set key "date" with value "20151120"
disconnected
Job tcontext ended at 12:04 21/04/2016.


But when trying to use this context value(date)-20151120 in another job, it passing null value instead of context value.
Can you please suggest weather my approach is correct or not?
Anonymous
Not applicable
Author

Can you put a screenshot up of your job structure please? You say "But when trying to use this context value(date)-20151120 in another job, it passing null value instead of context value.". Does that mean that you are trying to pass the context variable to a child job?
Anonymous
Not applicable
Author

Hi,
my requirement is i want set value to Context Variable dynamically and then i want to you that Context Variable in different jobs, say for example job1, job2, job3.. jobn.
Thanks,
Anonymous
Not applicable
Author

But how are you calling (starting) those jobs (1,2,3,etc) after the context variable has been set? You have to consider context variables to have a lifespan of an individual job, unless you actively pass them to a child job or write them to a file/db to be used elsewhere. You can't just set them in one job and expect them to be available in a disconnected job without doing anything
Anonymous
Not applicable
Author

RHall is correct. Each job is an isolated java class. You have to dynamically read the context variables in each class/job using the method I described.
Anonymous
Not applicable
Author

got it!! Thank you so much for your effort on this.
Anonymous
Not applicable
Author

Once you've loaded your Context, you can pass it through tRunJob either individually or by checking "Transmit whole context".
You do need to add the context variables to each Job that needs to reference them.