on 10-04-2013 9:24 AM
Hi,
I'm encountering context issues with my UDF.
This is the source
<root>
<objects>
<object>
<fields>
<custID>12345</custID>
<collections>
<postal>
<addressObject>
<fields>
<description>fake</description>
<street1>beijing</street1>
</fields>
<addressObject>
<addressObject>
<fields>
<description>official</description>
<street1>shangai</street1>
</fields>
<addressObject>
</postal>
</collections>
</fields>
</object>
<object>
<fields>
<custID>7890</custID>
<collections>
<postal>
<addressObject>
<fields>
<description>fake</description>
<street1>sydney</street1>
</fields>
<addressObject>
<addressObject>
<fields>
<description>fake</description>
<street1>melbourne</street1>
</fields>
<addressObject>
<addressObject>
<fields>
<description>official</description>
<street1>darwin</street1>
</fields>
<addressObject>
</postal>
</collections>
</fields>
</object>
</objects>
</root>
And this is the target with the expected output after mapping.
<root>
<objects>
<object>
<fields>
<custID>12345</custID>
<custAddress>shanghai</custAddress>
</fields>
</object>
<object>
<fields>
<custID>7890</custID>
<custAddress>darwin</custAddress>
</fields>
</object>
</objects>
</root>
Basically, I just need to retrieve the <street1> value of a particular <custID> that satisfies the condition <description> = 'official' and map it to <custAddress> field in the target. The rest of the description such as <fake> must be ignored. If the condition is not satisifed meaning no official description, then just past an empty string.
In my UDF, I'm passing the <description> and <street1>, with their context = <object>. Here's the function:
int i;
for (i=0; i<description.length; i++){
if (description[i].equals("official"){
result.addValue(street1[i]);
}
}
result.addValue("");
This is wrong as it fails in other test scenarios like when the 1st custID has no official address. Would really appreciate your inputs on this. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Just one suggestion, Wouldn't it work if you simply have an ifWithoutElse that if description = official, then send street1. After this have a mapWithDefault of blank value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I think ur UDF is incorrect, it should be something like this:
int count =0;
for (i=0; i<description.length; i++){
if (description[i].equals("official"){
count = i;
break;
}
}
if(count>0)
{
result.addValue(street1[count]);
}
else
{
result.addValue("");
}
Note - i am assuming that there would be only one "official" description that can come in one object node? In case no, then UDF needs to be modified.
Thanks
Amit Srivastava
Message was edited by: Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mark
Some questions.
All the <object> has an official address?
In this case, first you have to create an UDF with execution type "All values of a context"
Then you can look for inside <postal> and send the correct address
If not, you have to create an UDF with execution type "All values of a queue" and control when the <object> has no official address to suppress the value
Regards
Javi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.