cancel
Showing results for 
Search instead for 
Did you mean: 

Context/queue issue in UDF

markbernabe
Active Participant
0 Kudos

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!

Accepted Solutions (1)

Accepted Solutions (1)

gagandeep_batra
Active Contributor
0 Kudos

Hi Mark

You can check this using simple if else and remove context

Regards

Gagan

markbernabe
Active Participant
0 Kudos

Hi Gagan,

Thank you for this. But I believe this will fail when there's no official address for custID 1234. The address of 3214 will be assigned to 1234 and nothing will be mapped to 3214. Can you test that scenario? Thanks!

gagandeep_batra
Active Contributor
0 Kudos

ya i am assuming official address is always come.

what u you want if official address is not coming?

former_member184789
Active Contributor
0 Kudos

Hi Mark,

In the mapping suggested by Gagandeep, after the ifWithoutElse have a mapWithdefault of blank value i.e just before remove contexts, have a mapWithDefault.

markbernabe
Active Participant
0 Kudos

Hi Gagan,

Your logic worked plus the modification mentioned by Adarsh. Thanks a lot and also to Mark and Amit!

Answers (3)

Answers (3)

former_member184789
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

javier_alcubilla
Contributor
0 Kudos

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

markbernabe
Active Participant
0 Kudos

Hi Javier,

Not all <object> has official address so I'm using 'all values of a queue' in my UDF. It's possible that it only has fake address and that's when my mapping fails.

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

I'm using this mapping:

for fields/custID:

for custAddress:

UDF is modified abit (from Amit)

Result:

Result with all fake addresses (part 1) and two official addresses (part 2)

Hope this helps,

Mark