cancel
Showing results for 
Search instead for 
Did you mean: 

Context and Queue Mapping Problem 2

markbernabe
Active Participant
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

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

markbernabe
Active Participant
0 Kudos

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.

former_member187587
Contributor
0 Kudos

Can be done with standard mapping as well.

engswee
Active Contributor
0 Kudos

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

markbernabe
Active Participant
0 Kudos

Thanks Eng Swee! Really Appreciate the very detailed explanation.

Answers (0)