cancel
Showing results for 
Search instead for 
Did you mean: 

PI UDF Query

former_member183906
Active Contributor
0 Kudos

Hi,

I have a mapping requirement - I am providing source xml and target xml . Please try to help in it.

Mapping conditions -

(1) If D_3035 is BY and its D_3039 is 71694800 then take last 4 characters of D_3039 where D_3035 is DP

(2) If D_3035 is BY and its D_3039 is 007222200 then take removing preceding zeroes of D_3039 where D_3035 is CN

Source XML -

<G_SG2>

<S_NAD>

<D_3035>BY</D_3035>

<C_C082>

<D_3039>71694800</D_3039>

<D_1131>160</D_1131>

</C_C082>

</S_NAD>

</G_SG2>

<G_SG2>

<S_NAD>

<D_3035>SE</D_3035>

<C_C082>

<D_3039>00381636677</D_3039>

<D_1131>200</D_1131>

</C_C082>

</S_NAD>

</G_SG2>

<G_SG2>

<S_NAD>

<D_3035>DP</D_3035>

<C_C082>

<D_3039>00393363667</D_3039>

<D_1131>210</D_1131>

</C_C082>

</S_NAD>

</G_SG2>

Target XML - you can take any xml with a field A like - <B> <A> value </A></B>

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

Can you try this one:

Mapping:

Test:

Case 1

Case 2:

Regards,

Mark

markangelo_dihiansan
Active Contributor
0 Kudos

Minor correction, it is possible that the extracted last four digits might begin with a 0. Please use this instead.

Map

Regards,

Mark

Answers (1)

Answers (1)

former_member182412
Active Contributor
0 Kudos

Hi

You can try this UDF also.

Execution Type: All Values Of Context


public void groupByKeys(String[] d3035, String[] d3039, ResultList result, Container container) {

  Map<String, String> map = new HashMap<String, String>();

  for (int i = 0; i < d3035.length; i++) {

  map.put(d3035[i], d3039[i]);

  }

  if (map.containsKey("BY")) {

  if (map.get("BY").equals("71694800"))

  result.addValue(map.get("DP"));

  else if (map.get("BY").equals("007222200"))

  result.addValue(map.get("CN"));

  else

  result.addValue("");

  }else{

  result.addValue("");

  }

  }

Mapping:

D_3035--->removeContexts--->

                                             UDF----->Target

D_3039---->removeContexts-->

Regards,

Praveen.