Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tJava to tFileOutputDelimited returns null for initial value

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

 

 

Labels (2)
21 Replies
Anonymous
Not applicable
Author

Doesn't this have the same issue as before? The tJavaFlex returns the following files..

 

0683p000009M6ov.png

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"

 

TRF
Champion II
Champion II

The value for the 27th row is probably null
Anonymous
Not applicable
Author

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...0683p000009M6p0.png

 

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

TRF
Champion II
Champion II

"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?

Anonymous
Not applicable
Author

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"
    ]
}

 

Anonymous
Not applicable
Author

It looks like this is caused by your filename naming method. You say you have used this....

 

"C:/Users/users/Desktop/Ax_Orders/" + row2.fileName + ".csv"

@TRF used this....

 

"C:/Users/users/Desktop/Ax_Orders/" + ((String)row2.fileName) + ".csv"

If this fixes the problem please accept @TRF's solution

Anonymous
Not applicable
Author

Unfortunate this still has the same issue. The first row is exported as null.csv, second row is 1.csv.. etc.

They are all off by one number
Anonymous
Not applicable
Author

Can you take a screenshot of your job, your tJavaFlex and your file component settings please?

Anonymous
Not applicable
Author

No problem.. A few of the row names have changed since this morning but the job is still the same. See below;

 

Full job,0683p000009M6Zo.png

 

tFlowToIterate;

0683p000009M6dy.png0683p000009M6oh.png

 

tJavaFlex;

0683p000009M6nA.png0683p000009M6jI.png

 

OutputDelimited;

0683p000009M6pe.png0683p000009M6pj.png

Anonymous
Not applicable
Author

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 🙂