Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to use contexte variables in compnents developped with new component kit

Hi 

i'm migrating some components from java jet to the new component kit;

How to use contexte variables in compnents developped with new component kit.

Labels (2)
4 Replies
Anonymous
Not applicable
Author

Hi @Bilel.Charradi 

 

With new Talend Component Kit you don't need to implement anything special in your Component code to support context variables. Context variables are supported by Studio out of the box.

It works in following way:

1. Component option value goes to generated code without changes.

If user set a value with context variable he may see following Java code fragment in generated code

(click on "Code" tab to see generated code)0683p000009M20J.png2. In generated you may see that Map<String, Object> is created for Component options. Context variables are evaluated during this configuration Map setup. Map will hold evaluated context variable value (e.g. "myValue" string)

3. Then this Map is used to initialize Component. In Component code you will get evaluated context variable value (you will get "myValue" instead of context.input in Component code).

 

However, note that Components developed with new Component Kit support only static values (i.e. values which are not changed during Job runtime), because Component options are evaluated only once at the beginning.

 

If you have more questions don't hesitate to ask.

If you found some bug related to context variable value support, please create a ticket in our Jira for TUP (Studio) project.

 

Best regards,

Ivan Gonchar

serdarkilic
Contributor
Contributor

Hi Ivan,
From which object are we able to access global/context variables? I'm within the OnNext method in a processor and can't see an obvious way to get at these.
Anonymous
Not applicable
Author

Hi @serdarkilic 

 

It is not possible to access global/context variables directly in Component code. 

You may set global/context variable as value of Component UI property.

Then global/context variable value will be evaluated during Job code execution and set as value of Component Configuration class (a POJO class which defines Component properties)

In your Component code you may get variables values as values in your Configuration class.

bsimakis
Contributor
Contributor

Hello,

 

I have tried this solution and while it works for context variables, it is treating the global variables as text (i.e. I get "jobName" output instead of the actual name of the job) 

 

I have included below a screen shot of the configuration in my studio and code for the configuration object and object for the list below.  

 

Configuration (Studio 7.1.1) 

0683p000009M7YF.png

 

Configuration object:

0683p000009M7YU.png

 

List object:

0683p000009M7SN.png