on 02-26-2015 7:36 AM
Hi Experts,
Source:
<Source>
<Data>
<Name>Mike</Name>
<Address>
<Country>DE</Country>
<Country>SE</Country>
<Country>US</Country>
</Address>
</Data>
<Data>
<Name>James</Name>
<Address>
<Country>AT</Country>
<Country>AU</Country>
</Address>
</Data>
<Data>
<Name>John</Name>
<Address>
<Country>US</Country>
<Country>FR</Country>
<Country>TH</Country>
<Country>MY</Country>
</Address>
</Data>
</Source>
Target:
<Target>
<Data>
<Name>Mike</Name>
<Status>Approved</Status>
</Data>
<Data>
<Name>James</Name>
<Status>Denied</Status>
</Data>
<Data>
<Name>John</Name>
<Status>Approved</Status>
</Data>
</Target>
Requirement:
<Status> in Target will be 'Approved' only if <Country> = US exists. If there's no <Country>=US, then the <Status> will be 'Denied'.
We created UDF (All values of Queue) but it's not working if the <Data> node in source is more than 1.
for (int i=0; i < country.length; i++){
if (country[i].equals("US")){
result.addValue("Approved");
break;
}
}
result.addValue("Denied");
Appreciate any inputs regarding this.
Thanks a lot.
Hi Mark
Try the following UDF with "All Values of Context" instead. Change the context of the source field Country to be under Data.
boolean foundUS = false;
for (int i=0; i < country.length; i++){
if (country[i].equals("US")){
result.addValue("Approved");
foundUS = true;
break;
}
}
if (!foundUS) {
result.addValue("Denied");
}
Rgds
Eng Swee
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Eng Swee. It worked. Our UDF worked as well. It must have been with the execution type. I also encountered this weird problem where the UDF was not working when it's in the Function Library. But when we copied the same exact code to local function, it worked fine. I restarted ESR and now everything is ok.
Hi Mark
You are welcome.
Yes, your UDF would work by just changing the execution type, but only by sheer coincidence.
The following would be the output of your UDF. There will always be a "Denied" entry in each context. It just happens that your target field only occurs once under each parent (one Status under each Data), then only the first entry of each context is used. If there were multiple occurrence of the target field, it would have caused a problem.
By having the additional flag to determine if US is found, the generated output will only have 1 value per context which matches the target field occurrence.
Hope this explanation is helpful.
Not too sure about the function library part, I don't notice anything peculiar about the code that would prevent it from working. Maybe sometimes PI is a bit iffy on this
Rgds
Eng Swee
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.