Four Stars

how to looping job with if statement in talend?

hi all,

 

I'm trying to extract XML data from a website using the tRestClient API, in the first step i am getting value max_page from Mysql database, then it used for URL in tRestClient and the next step parsing the XML with tExtractXMLField and then saved into databases

 

Untitled4.png

 

 

but i need to repeat my job from first step if tExtractXMLField column status = SUCCESS, and stop when column status = FAILED

Untitled5.png

 

 

 

Regards,

 

Jakson

 

5 REPLIES
Fifteen Stars

Re: how to looping job with if statement in talend?

You can do this with a tLoop and a globalMap variable. For an example of something similar (similar in that a loop carries on until something in the processing changes) take a look here: https://www.rilhia.com/tutorials/using-talend-get-your-spotify-listening-history-facebook

Look for the section with the heading "The GetMySpotifyListeningHistory Job" and take a look at how that works.

 

Essentially you want to create a globalMap variable to hold your status value. Base the tLoop on the contents of that value (true/false). Pre-set that globalMap with the value true. Base the tLoop logic on the presence of "true" in the globalMap variable. 

 

You can store your success value in the globalMap for every row either using a tJavaFlex or a tSetGlobalvar component.  

Rilhia Solutions
Four Stars

Re: how to looping job with if statement in talend?

Hi,

 

Is the link to the tutorial broken? I can't seem to get it to work.

 

Thanks,

Scott

Nine Stars

Re: how to looping job with if statement in talend?

you can just add tLoop and a tDie (linked by an if link) to get out.

Francois Denis

Don't forget to tag when it's "solved"!

Fifteen Stars

Re: how to looping job with if statement in talend?

Sorry about my site @ScottLeckie. My server was attacked by some Russian hackers (according to their IP addresses anyway) and I had to take it down. Unfortunately I have not been able to find the time to rebuild it. I will get the tutorials back online as soon as I can though.

 

In the meantime, the way to approach this problem is to use a tLoop with a While loop based on a value that can be changed after each loop. In my example I used the While loop's conditional variable to hold the URL I needed the web service to call. Before the tLoop I would set the initial URL and use the tLoop to iterate over service calls. Each time the service was called it would return some XML and if the results required another service call, it would supply another URL. I would extract that from the dataset and add it to the tLoop's conditional variable that the While loop is based on. If there was no URL returned, I would set the conditional variable to null and that would stop the tLoop.

Rilhia Solutions
Four Stars

Re: how to looping job with if statement in talend?

Many thanks @rhall_2_0. I'll give it a try and also look out for tutorials coming back online Smiley Happy

 

Cheers,
Scott