cancel
Showing results for 
Search instead for 
Did you mean: 

How to read collection in groovy script - Message Mapping Scenario

former_member595526
Active Participant
0 Kudos

Hi Experts,

I have requirement in message mapping of iFlow, which is to read a collection of strings and concatenate it together and map to one of the target fields.

I am not sure how to do it as I am new to CPI side. Please help me out how to map it.

I have a source node which comes as list, I have to read this and set to target field

Thanks in Advance

Accepted Solutions (0)

Answers (2)

Answers (2)

Sriprasadsbhat
Active Contributor

Hello Ansari,

Below will do the same.Make sure you have set the right context in source field and set the P1 in your custom function as array like below

import com.sap.it.api.mapping.*
def String extParam(String[] P1 , MappingContext context) 
{    
    //Your processing will go here
    //P1[0] will have first value P1[1] will have second and so on....
    String v = P1[0].toString();
    return pval;
    
}

Regards,

Sriprasad Shivaram Bhat

former_member595526
Active Participant

Hi Sriprasad,

The moment add [](square bracket in the String param, I am unable to save the script. It keep gives me error saying Script contain no valid function.

Removing [] square bracket from String param works fine. No clue.

getting below error for above code while click on OK button in SAP CPI Web UI

Pls help me out on this

apu_das2
Active Contributor
0 Kudos

Hi,

On top of the GSH shared above, when input will be given in this custom function in the MM user remove context node function before providing the input.

To concatenate modify the script like below -

for (int i=0; i<p1.length; i++)

String v = P1[i].toString().concat("");

return v;