cancel
Showing results for 
Search instead for 
Did you mean: 

Help regarding UDF

Former Member
0 Kudos

Hi

My logic is

if txt=os then pass UA

or

if txt=gs then pass TA

else

pass DEL

here txt comes in a segment which comes multiple times.let me say for example if an idoc is coming with 3 segments and txt=gs is in the last segment then output should be TA.

I wrote and udf(Value) using normal if else conditions but it's returning the value DEL as txt in first segment is someother value. But i need to consider all 3 segments and then return the output value. How to handle this contexts.please help me.

PS:Target field is 1:1 occurance

TIA

Accepted Solutions (1)

Accepted Solutions (1)

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

>>>>let me say for example if an idoc is coming with 3 segments and txt=gs is in the last segment then output should be TA. But i need to consider all 3 segments and then return the output value...

Does it mean you've to consider the last occurrence of the segment...or you want to give any priority to any segment????

If you want to consider the last occurrence then set the UDF type as allValues of queue and consider the last value of the input array....Can you post sample input and expected result sothat I can provide you the UDF logic

Regards,

Priyanka

Former Member
0 Kudos

i need to consider all the 3 segments which contains TXT. and if anysegment contains the txt value which equals the above condition. Then pass the resp value

i know i need to use queue udf but i dont know how to write it.

Former Member
0 Kudos

Execution type: all values of context

txt-removecontext-target


int count=0;

for(int i=0;i<var1.length;i++)
{
if(var1<i>.equals("os"))
{
result.addValue("UA");
count =count+1;
}
if(var1<i>.equals("gs"))
{
result.addValue("TA");
count =count+1;
}
}
if(count==0)
{
result.addValue("del");
}

what if ur input queue will have both the values like os and gs..in that case how will u take ur output??

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Please use following code-

String val = (String) container.getTransformationParameters().get(StreamTransformationConstants.SENDER_SERVICE);


int index = val.length();

String sub = val.substring(index-2, index);

Integer lv_src = Integer.parseInt(src);
src = lv_src+"";

if (sub.equals("US"))
{
src= "US-" + src;
}
else if (sub.equals("SW"))
{
src= "SW-" + src;
}
else if (sub.equals("UG"))
{
src= "UGL-" + src;
}

return src;

Adjust it to suit your need and it should work.

Former Member
0 Kudos

What is that? i didnt get it. Tat post is for this thread?

Former Member
0 Kudos

can u please paste ur source and target structure??