Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a job which parses a CSV output from an API. I am trying to dynamically set the file name, however, the first result of order number is always null, and then rest is 1 off.
The orderNumber shows correctly using System.out.println() in the tJava, so I'm assuming its something to do with the order that things are executed?
I have attached screenshots of both components & the workflow of the job.
Is there a way around this? I can't extract the order number directly from the JSON because its just a data object with csv inside of it.
Thanks
Doesn't this have the same issue as before? The tJavaFlex returns the following files..
instead of 1 to 27.
What does your file name look like in the job above? Mine is currently set to "C:/Users/users/Desktop/Ax_Orders/" + row2.fileName + ".csv"
It's not, I can see the data clearly using postman, and if I open the file which has been saved as null.csv, the row starts as below...
Is this not the same problem that we had at the start, where you said that tJava runs first?
I'm open to changing the layout of the job I just need a resolution, I don't feel like this should be as hard as its proving to be!
Thank you for your help so far, I appreciate it
edit; the first row it coming through as "null" and then the following ones are a number off, eg 1.csv SHOULD be 2 if you do the substring manually
"Is this not the same problem that we had at the start, where you said that tJava runs first?"
No, when using tJavaFlex, initial code starts first and only once, main code starts for each row and final code starts last and only once.
Well... can you share your JSON?
Here's a snippet of the JSON, the first two records (of the 27 which were being used previously)
{
"message": "Fetched order(s)",
"data": [
"1,,,,,,,,,,,\"Admin Test\",\"11 Avenue\",City,UK,,POSTCODE,,2019-07-26T09:39:21+00:00,,,,,,,,,,,,,,2019-07-26T09:39:21+00:00,Y,,,,,Y,,,,,,,,,,,,\n1,,DELIVERY,DELIVERY,1,,,5.00,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n2,,SUPPu18024,AXb98017,1,,,12.54,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n3,,SUPPLEFTSLEEVE,LEFTSLEEVE,1,,,2.50,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n4,,LOGOSETUPFEE,LOGOSETUPFEE,1,,,10.00,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n",
"2,,,,,,,,,,,\"Admin Test\",\"11 Avenue\",City,UK,,POSTCODE,,2019-07-26T09:39:21+00:00,,,,,,,,,,,,,,2019-07-26T09:39:21+00:00,Y,,,,,Y,,,,,,,,,,,,\n1,,DELIVERY,DELIVERY,1,,,5.00,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n2,,SUPPu18024,AXb98017,1,,,12.54,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n3,,SUPPLEFTSLEEVE,LEFTSLEEVE,1,,,2.50,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n4,,LOGOSETUPFEE,LOGOSETUPFEE,1,,,10.00,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n"
]
}
Can you take a screenshot of your job, your tJavaFlex and your file component settings please?
No problem.. A few of the row names have changed since this morning but the job is still the same. See below;
Full job,
tFlowToIterate;
tJavaFlex;
OutputDelimited;
OK, I see the issue. It's caused by the way in which file components work. When you iterate, everything after the iterate link is treated as a subjob in its own right. A file component is initiated at the beginning of a subjob....before any data has been processed. So, as you are creating your filename at the beginning of the subjob, the file component for the first run is not given a name (the data has not been processed by the tJavaFlex component. The way to get around this is to put a tJava before your tJavaFlex and link to the tJavaFlex with an iterate link. You there therefore have two iterate links; one before your tJava and one before your tJavaFlex. In the tJava component put the following code.....
String orderString = ((String)globalMap.get("extractedDate.data"));
String orderNumber = orderString.substring(0, orderString.indexOf(','));
globalMap.put("filename", orderNumber);
Then you can either leave the tJavaFlex data exactly the same (maybe remove the filename bit) and use this in your filename field....
"C:/Users/users/Desktop/Ax_Orders/" + ((String)globalMap.get("filename")) + ".csv"
That should do it.
Again, this is what @TRF was suggesting, so it is probably only fair to give him the solution 🙂