cancel
Showing results for 
Search instead for 
Did you mean: 

User Defined Function - Existence Check

Former Member
0 Kudos

Hi all,

We have the following requirement:

SOurce:

< Header/>

.....

<items 0 to unbounded/>

<item_status/>

.....

Target:

<Header/>

<Header_status/>

...........

.....

...

The Header Status on the target needs to be populated based on the following req:

If all Source items status = A, Target Header status = 0

all Source items status = B, Target Header status = 1

otherwise Traget Headr Status = 3

Please let me know if this can be hnadled with out use of user defined funtion.

Thanks for your help in advance,

Balaji

Accepted Solutions (1)

Accepted Solutions (1)

MichalKrawczyk
Active Contributor
0 Kudos

hi,

>>>>all Source items status = B,

this cannot be handled without user defined function

Regards,

michal

Former Member
0 Kudos

Hi Mike,

Coud you please elaborate?

Thanks

Balaji

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

sure:)

if you want to loop through all elements

you need to use Advanced user defined function

(in the message mapping)

in which you'll have all of your elements

as an array - so you'll be able to check

if they all are = B

this is the easiest way to achieve what you need

Regards,

michal

Former Member
0 Kudos

Michal,

Thanks for your quick responses.

As I am not a java guy, could you help me in writing Adv User Defined Function.

Regards,

Balaji

Answers (2)

Answers (2)

former_member187339
Active Contributor
0 Kudos

Hi,

Create a Advanced UDF with cache as Queue and try this code:

public void Status_test(String[] item_status,ResultList result,Container container)

{

int j=0,Status_A=0, Status_B=0;

for (j=0;j<item_status.length;j++)

{

if (item_status[j].equals("A"))

Status_A++;

else if (item_status[j].equals("B"))

Status_B++;

}

if (Status_A==item_status.length)

result.addValue("A");

else if (Status_B==item_status.length)

result.addValue("B");

else result.addValue("C");

}

Regards

Suraj

Former Member
0 Kudos

Let me take a shot at this.....

LBL_A = (item_status -- removecontext -- sort -- splitbyvalue(valuechanged) -- collapsecontexts -- removecontext)

LBL_A -- count 
              
               equalsA -if --               /                
 constant(1)

then -- LBL_A
             
              equalsS -- then output="0" else output = "1"
             /
constant A

there is not enough space to write it here...:( ...hope you get the idea...how to go about doing it....

definitely it is do-able without a udf....

Thanks,

Renjith