cancel
Showing results for 
Search instead for 
Did you mean: 

mapping: how to send the LAST value of a queue

former_member440449
Participant
0 Kudos

Hi Gurus,

I need a target field to receive the last value of a source field, as you can see below:

Source:

SourceSegment(1..unbounded)
->SourceField(0..1)

Target:

TargetSegment(1..1)
->TargetField(0..1)

I have an example asi this:

<SourceSegment>
<SourceField>A</SourceField>
</SourceSegment>

<SourceSegment>
<SourceField>B</SourceField>
</SourceSegment>

<SourceSegment>
<SourceField>C</SourceField>
</SourceSegment>

So, what I need is to send the LAST value in the TargetField which will be generated only once:

<TargetSegment>
<TargetField>C<TargetField>
<TargetSegment>

Is this possible without an UDF?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Write a simple Queue cached udf and set the context of source element to top node.

public void lastvalue(String[] a,ResultList result,Container container){
 int x;
String y = "";
x = a.length;
y = a[x-1];
result.addValue(y);
}

baskar_gopalakrishnan2
Active Contributor
0 Kudos

If you want still to make the code elegant ... Please simply this way

public void lastvalue(String[] a,ResultList result,Container container){
  result.addValue(new String(a[a.length-1]);
 }

Former Member
0 Kudos

Hi,

You will not be able to do this using the standard functions. Use the UDF examples already provided above. Use the queue function.

Regards

Answers (1)

Answers (1)

VijayKonam
Active Contributor
0 Kudos

get the array size in the UDF and assign the last element of the array to the target element. Something like -

String len = input.length;

output = input[len-1];

VJ