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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Get "value" of current context in a query

Hi,
I need to do a query like

SELECT * FROM mytable WHERE talend_context = '[INSERT CURRENT VALUE OF CONTEXTNAME HERE]';

How can I do this? What variable should I reference?

Labels (2)
6 Replies
Anonymous
Not applicable
Author

In your t{DB}Input component, you will notice that the SQL is within quotes. It is basically a Java String. All you need to do is build your query (its good practice to name your columns explicitly by the way) and then concatenate your context variable to the query like below....

"SELECT Col1, Col2, Col3 FROM mytable WHERE talend_context =" +context.yourVal


You do not need the semi colon. If you are concatenating a String value, then you will need to add single quotes, for example....

"SELECT Col1, Col2, Col3 FROM mytable WHERE talend_context ='" +context.yourVal +"'"


As I said, all you are doing is building a query String in Java. So as long as your String results in a legitimate SQL (and your columns match your schema), it will work.
Anonymous
Not applicable
Author

Thanks, I get that, but what I need is the name of the actual CONTEXT the job is running under (i.e. "default" or "production") etc
Anonymous
Not applicable
Author

The job will be run for that CONTEXT. There is no switching that mid job. What you can do if you simply need to know the CONTEXT (maybe that derives some other logic.....but it shouldn't) is to create a context variable which shows the name of the CONTEXT. However as I said, logic should not really be derived from the CONTEXT. CONTEXTs are meant to make it easy for you to easily switch environments (DEV, TEST, UAT, PROD, etc) without needing to make changes to the actual job. 
Anonymous
Not applicable
Author

Slight alteration to my last post. I forgot that there is a String variable built into every job called "contextStr". This can be used in any component as it has its value assigned at the beginning of the job. This will hold the name of your context.

You seem to know Java. As such you can find lots of this stuff out by looking at the source that is generated by Talend. Click on the "Code" tab in the bottom left of the development workspace. This will force the code to rebuild and is useful for finding errors as well.
Anonymous
Not applicable
Author

Yes "contextStr" is exactly what i need. This is for auditing, not logic alteration
Attn: Talend. This stuff should all be clearly documented somewhere. So much of this stuff is vauge and obscure info that is not in any talend docs. Try searching talend's "Help" center, for "contextStr". ZERO matches anywhere!
Anonymous
Not applicable
Author

You learn more by searching the source code than reading the documentation with Talend. Part of me finds this frustrating, part of me likes this because it means you still need some technical skills to use it (after you have been made aware of this of course). You sound like someone who can delve into code. Take a look and you will learn so much quicker than reading any documentation.