cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script to concat and split

10-17-2023 6:02 PM
learninghubx01 Explorer
1735 views 2 comments
0 Likes
SAP Managed Tags
Subscribe

Hi All,

I have a requriement in CPI mapping where the value of the field1 and field 2 from the source need to be concatenated and then the length of the field1 is checked , if the length is greater than 20 characters then the first 20 characters need to be sent to the field1 on the target side and rest of the characters need to be sent to the second field on the target side. Kindly help me with the script code for this.

0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

Bais
Participant
0 Likes

probably you are talking about mapping issue, on Message mapping you can create the logic, or just send 2 fields on groovy custom function and use the result.

Groovy online compiler

Groovy CPI like compiler

def String exampleValue(String field1, String field2, Output first20, Output restOfus) {
	//Your code here
        def result = field1+field2;
        if (result.length() > 20)
            first20 = result.substring(0,20)
            resfOfus = result.substring(20,result.length())
	return result;
}

//def result = exampleValue("field1_string_example_VERYVERYVERYVERYVERYVERYLONG","field2_string_example")

//println(result)
//println(result.length())

I'm not sure about code, is it late night here.

BurakYi
Participant
0 Likes

Hi Rakesh,

if you can provide more information or sample message(XML, CSV, Json) with header and properties, I can try to help you.

Thanks,

Burak