Wednesday, April 27, 2022

Groovy Script to read the data in the same field level and send it all values in one field.

Using Groovy Scripts to read the same field level and send it all values in one field.

Read the input value in field name -SAPScriptLineText

Now 2 same fields come 2 different values i need to concat and send to receiver 1 value using groovy script.

Input:

<SAPScriptLineText>BG AV 302 LED BG AV 302 LED BG AV 302 LED BG AV 302 LED BG AV 302 LED BG</SAPScriptLineText>

<SAPScriptLineText>AV 302 LED BG AV 302 LED BG AV 302 LED</SAPScriptLineText>

Output:

<SAPScriptLineText>BG AV 302 LED BG AV 302 LED BG AV 302 LED BG AV 302 LED BG AV 302 LED BG AV 302 LED BG AV 302 LED BG AV 302 LED</SAPScriptLineText>

Example:

Below Script can use the inside Mapping of groovy script.

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

def void addConcatText(String[] input, Output output, MappingContext context)
{
    String final_value = "";
    for(int i=0; i<input.length; i++)
    {
        final_value += input[i]
    }
    output.addValue(final_value)
}

Screenshot:

Groovy Script name: addConcatText.









No comments:

Post a Comment

The sender will pass the data in JSON format without converting it to XML format. We need to read the particular field.

The sender will pass the data in JSON format without converting it to XML format. We need to read the particular field to check the conditio...