cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenate structure into one field

former_member197479
Active Participant
0 Kudos

Hello experts,

I am working with Cloud Platform Integration, but I headed into this speed bump:

I have the following XML Format:

<root>
<textContent>First Text</textContent>
<textContent>Second Text</textContent>
</root

As you can see, I have 2 different texts, each one inside a tag (textContent) I wish to concatenate those two texts and pass them into a single tag within the target:

<targetRoot>
<text>First Text, Second Text</text>
</targetRoot>

I tried a lot of different things, split by value, then concatenate, remove contexts, however it assigns just the last text, and I need it to iterate for each <textContent> concatenate them and sent them int only one target tag.

Does anybody have insights of what am I missing here?

Regards,

Accepted Solutions (0)

Answers (1)

Answers (1)

Sriprasadsbhat
Active Contributor

Hello Melvin,

You need to create custom function to achieve the same.Below is how you can do it.

Custom Function Script:

import com.sap.it.api.mapping.*;

//Add Output parameter to assign the output value.
def void custFunc2(String[] is, Output output, MappingContext context) 
{
    def outputVal="";
        for ( int i=0;i<is.length;i++)
        {
        outputVal= outputVal + is [i]
        }
        output.addValue(outputVal);
}

Screenshot of Mapping:

Regards,

Sriprasad Shivaram Bhat

MortenWittrock
Active Contributor

Hi Sriprasad

You missed the comma separation of the values. The function can be reduced to:

import com.sap.it.api.mapping.*

def void appendQueue(String[] strings, Output output, MappingContext context) {
    output.addValue(strings.join(", "))
}

Regards,

Morten