cancel
Showing results for 
Search instead for 
Did you mean: 

Splitting a string with a delimiter in CPI using groovy script

mohan_reddy1
Explorer
2,729

Hi Experts,

can you please help with your valuable inputs for my below requirement.

I receive payload which contains below values for one of the field in my source structure and these values need to be split and needs to pass different fields in the target structure.

Input : ORDERS05,ORDERS05_01,ORDERS,n.a.,n.a.,SAPXXX,XXXCLNT000,LS,LS,ONECPI,AB_CD_YYYY,LS,n.a.

expected output:

field1:ORDERS05

field2:ORDERS05_01 and so on....

View Entire Topic
0 Kudos

Hi Mohan,

You can probably split that input string by using "," as a delimiter and then capture the result into a list. Use the resulting list then to create your output structure.

Sample Code:

def Input = "ORDERS05,ORDERS05_01,ORDERS,n.a.,n.a.,SAPXXX,XXXCLNT000,LS,LS,ONECPI,AB_CD_YYYY,LS,n.a"

def OutputList = Input.split(',').collect{it as String}

Hope this helps.

Best Regards,

Amal

mohan_reddy1
Explorer

Thanks so much for your inputs.

Dagmar
Explorer
0 Kudos
Hello, if I want to split this String 2024-12-04 07:09 UTC, and as an output, I need: 20241204, how is that achieved please? ".collect" does not work for me. Thank you
radinator
Participant
0 Kudos
@Dagmar first you need to get the substring of the first 10 chars to have the entire date then split that text by the dash and finally compose your ISO date. String sample = "2024-12-04 07:09 UTC"; def parts = sample[0..10].split("-").collect{it as String}; String date_in_ISO = parts[0] + parts[1] + parts[2]; println(date_in_ISO);