One Star

[resolved] Issue with tAdvancedFileOutputXML, null pointer if file is a variable

My job is trying to generate multiple XMLs. 
Something like I look up the main record, then get all the related records, then generate 1 xml file per main record.
for example, Look up Class, get details. Look up students, get list of students. XML is something like 

<CLASS>
<ROOM/>
<TIME/> 
<STUDENTS>
<PERSON>
<NAME/>
<AGE/>
<STATUS/>
</PERSON>
<PERSON>
<NAME/>
<AGE/>
<STATUS/>
</PERSON>
</STUDENTS>
</CLASS>



My problem is each class will be a seperate XML and tAdvancedFileOutputXML seems to have issue using a dynamic variable as the file path. I'm trying to make each file to be "CLASS".xml but 
Any one have a solution?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: [resolved] Issue with tAdvancedFileOutputXML, null pointer if file is a variable

Hello 
It is impossible to access the global variable in the same flow, you need to group the records by class ID and filter the records for each class ID, write each group records to corresponding file.

 1.png

Here I upload a demo job, I hope it will give you some tips. Let me know if you have any questions.
Regards
Shong
forum56553.zip

----------------------------------------------------------
Talend | Data Agility for Modern Business
5 REPLIES
Community Manager

Re: [resolved] Issue with tAdvancedFileOutputXML, null pointer if file is a variable

Hello
Please provide more details about your problem, what are you input data? What are your expected result? Where do you use variable?
Regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Issue with tAdvancedFileOutputXML, null pointer if file is a variable

The error I get is:
Exception in component tFileOutputXML_1
java.lang.NullPointerException
at java.io.File.<init>(Unknown Source)
at importtalend.testarea_0_1.testArea.tMSSqlInput_1Process(testArea.java:3568)
at importtalend.testarea_0_1.testArea.GetDBConfig_1_tJava_1Process(testArea.java:1518)
at importtalend.testarea_0_1.testArea.GetDBConfig_1_tMSSqlConnection_1Process(testArea.java:1376)
at importtalend.testarea_0_1.testArea.GetDBConfig_1_tFileInputDelimited_1Process(testArea.java:1106)
at importtalend.testarea_0_1.testArea.tJava_1Process(testArea.java:5932)
at importtalend.testarea_0_1.testArea.runJobInTOS(testArea.java:7964)
at importtalend.testarea_0_1.testArea.main(testArea.java:7798)
: importtalend.testarea_0_1.testArea - tFileOutputXML_1 null

my input is 
|=-------+-------+------+------+----+-------=|
|CLASS |ROOM |TIME |NAME |AGE |STATUS |
|=-------+-------+------+------+----+-------=|
|CLA001 |Rm02 |10:00 |Bob |22 |Enrolled|
|CLA001 |Rm02 |10:00 |John |25 |Enrolled|
|CLA001 |Rm02 |10:00 |Fred |23 |Enrolled|
|CLA002 |LCT5.1 |16:00 |John |25 |Enrolled|
|CLA002 |LCT5.1 |16:00 |James |21 |Enrolled|
|CLA003 |Rm05 |20:30 |John |25 |Enrolled|
|CLA003 |Rm05 |20:30 |Dick |21 |Enrolled|
|=-------+-------+------+------+----+-------=|

And I'm expecting 3 XML files. 
CLA001.xml
CLA002.xml
CLA003.xml
After I get the data, I pass it through a javarow and globalMap.put("classID", *value*)
And in my tAdvancedFileOutputXML I put  (String)globalMap.get("classID")  as my File Name
Community Manager

Re: [resolved] Issue with tAdvancedFileOutputXML, null pointer if file is a variable

Hello 
It is impossible to access the global variable in the same flow, you need to group the records by class ID and filter the records for each class ID, write each group records to corresponding file.

 1.png

Here I upload a demo job, I hope it will give you some tips. Let me know if you have any questions.
Regards
Shong
forum56553.zip

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

Re: [resolved] Issue with tAdvancedFileOutputXML, null pointer if file is a variable

Thanks Shong, managed to get it to work.
I just added a flowToIterate in my job and got it to work.
Community Manager

Re: [resolved] Issue with tAdvancedFileOutputXML, null pointer if file is a variable

Great, thanks for your feedback!
----------------------------------------------------------
Talend | Data Agility for Modern Business