Output values from tJava and input it in trigger "Run if"

Highlighted
Five Stars

Output values from tJava and input it in trigger "Run if"

Hello,
I would like to execute one action or another depending on the result of a tJava component.
If the job runs before 15:00, the trigger (if_10_15) will be executed.
If the job is executed after 15:00, it will be the trigger (if_15_18) that will be executed.
I do not know how to do this. I put an exit in each of my conditions of my tJava (row1.etat) and connected it via a trigger "Run if" containing the conditions if (row1.etat == -1), if (row1.etat == 0) and if (row1.etat == 1).
But I have some errors.
If anyone could show me the right way, it would be nice.
Thank you in advance.


My tJava code :

SimpleDateFormat dateformat = new SimpleDateFormat("hh:mm"); 
Date hLim = dateformat.parse("15:00"); 
String pattern = "HH:mm"; 
Date hNow = new Date();
int etat = TalendDate.compareDate(hNow, hLim, pattern);

// Faire passer la valeur de etat en argument au "Trigger Run if" 
if (etat == -1){
	System.out.println(etat + " / " + hNow + " / " + " Tournée demain matin");
	row1.etat = etat;
} 
if (etat == 0){
	System.out.println(etat + " / " + hNow + " / " + " Tournée demain matin");
	row1.etat = etat;
} 
else if (etat == 1){
	System.out.println(etat + " / " + hNow + " / " + " Tournée demain après-midi");
	row1.etat = etat;
}

My job structure :

JobListesTourneesBaches.JPG

Moderator

Re: Output values from tJava and input it in trigger "Run if"

Hello,

What's the error are you getting when you use tJava custom code in your job?

Here is a component tWaitForFile which iterates on a directory and triggers the next component when the defined condition is met.

https://help.talend.com/reader/HP30FGhc6Q9LiHefZVu4yw/xygPn~ESNbYiVEUQlhIr9A

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Eight Stars

Re: Output values from tJava and input it in trigger "Run if"

Hi,
Variable defined in tJava has a scope in the Run-If connection.
I would do:
boolean runMorningTour = TalendDate.compareDate(hNow, hLim, pattern) <= 0;
Then if the runif, respectively, runMorningTour and !runMorningTour

Cheers,
Navds

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Have you checked out Talend’s 2019 Summer release yet?

Find out about Talend's 2019 Summer release

Blog

Talend Summer 2019 – What’s New?

Talend continues to revolutionize how businesses leverage speed and manage scale

Watch Now

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog