Using tSetGlobalVar

One Star

Using tSetGlobalVar

Hello,

I want to define a global variable for a whole job, but as I don't know the Java language, it's hard to find what's wrong.
I defined an object tSetGlobalVar_1 where I added a variable with key "filtre" associated with a value "PNOM". But how to use it, for example in a tJava object with a simple println ?
Thanks.
Thomas
Employee

Re: Using tSetGlobalVar

You can try :
System.out.println(globalMap.get("filtre"));

Regards
One Star

Re: Using tSetGlobalVar

Thanks, this solves my issues.
One Star

Re: Using tSetGlobalVar

I need to fetch configuration values such as the database credentials from an xml file. Store these in global variables.
Then use the content of global variables in another job .
To implement this I used the following steps
1) In Job one i used tFileInputXML ----> tJavaRow (store all values in context) --- on component OK --> tSetGlobalVar ( store values from context to variable inside tGlobalVar)

2)In job two I used tRunJob (call job one) ------ on Component OK ------>tJava ( print all the global variables defined in job one)
Execution of job two prints null for all the global variables defined in job one.
Can any body let me know where might be the problem ? and provide me a sample job to implement this.
Thanks and Regards,
Pravu Mishra.
One Star

Re: Using tSetGlobalVar

you have to call the job 2 from the first one and set the Transmit Whole Context
cheers
One Star

Re: Using tSetGlobalVar

Hi,
Thanks for your reply.

If you say job one must call job two then I feel there is no point to define job two. I can do all these in job one which I do in job two.

I need to call the job one once from another dependant job. Job two is dependant on job one. Hence job one will be called from job two.
I may also call the job one from another job (job three) that is dependant on job one.
What you said may not be appropriate for this problem.
Thanks and Regards,
Pravu Mishra
One Star

Re: Using tSetGlobalVar

I am using tSetGlobalVar and tJava components. One key "FILE_EXISTS" is defined in tSetGlobalVar,
and the code inside tJava component is
System.out.println(globalMap.get("FILE_EXISTS"));
When I run the job null is printed out, even though the value for "FILE_EXISTS" is different. Please suggest
Community Manager

Re: Using tSetGlobalVar

Hello
When I run the job null is printed out, even though the value for "FILE_EXISTS" is different. Please suggest

Hava you set a value to key 'FILE_EXISTS'? and the job should be:
tSetGlobalVar--Onsubjobok-->tJava
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Using tSetGlobalVar

tSetGlobalVar-- Onsubjobok (this was missing in my job) -->tJava.
After putting -- Onsubjobok -->tJava, it works.
Thanks a lot Shong.
One Star

Re: Using tSetGlobalVar

I have a onejob where the tSetGlobalVar component is placed. How do i set a value to key(tSetGlobalVar)n my onejob from my secondJob. Please suggest.
Community Manager

Re: Using tSetGlobalVar

Hello
I have a onejob where the tSetGlobalVar component is placed. How do i set a value to key(tSetGlobalVar)n my onejob from my secondJob. Please suggest.

1)In onejob, define a context variable, eg:myVarName(string), set the value of key(tSetGlobalVar) as context.myVarName.
2)In secondJob, use a tRunJob to run onejob, on tRunJob, set value to context variable defined in onejob.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Using tSetGlobalVar

Actually i am using the tRunJob to run the secondJob from my oneJob, and inside the secondJob i want to set the VALUE for KEY("FILE_EXISTS") inside the oneJob.
I tried putting a code in tJava in secondJob as - globalMap.put("FILE_EXISTS", "TRUE");
But value returned will be null inside oneJob.
Please suggest.
One Star

Re: Using tSetGlobalVar

For solving these kind of issues, I used java singleton object and placed all the variables those are required in all or most of the jobs. The main job places the values in singleton object and other jobs those are called from main job uses the values placed in the singleton object.
Example : The database credentials are placed in Singleton object and the oher sub jobs uses these database credential placed in Singleton object.
Hope you know what is a singleton object. Incase you do not know what is a singleton object, then please get the information from net.
There is an example job placed at http://www.talendforge.org/exchange/tos/extension_view.php?eid=156 and it uses singleton object.
I guess your problem will also be solved in case you use Singleton object and the example found at the above URL explanes it clearly.
Thanks and Regards,
Pravu Mishra.
One Star

Re: Using tSetGlobalVar

I have a job where data is laoded from a CSV file into a MS SQL Server DB. Data is rejected from both the CSV and DB. I want to have a total count of rejected records.
CSV--->DB ----> (rejected) tjavaflex ----> report file
|
|
|
tjavaflex----> report file
My job will first reject the CSV records and then the DB ones. Can I get the count of Rejected Records and how to use it in tjavaflex component so that after a limit is reached, I end my job