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.









Friday, April 8, 2022

Groovy Scripts to read the date and time and reduce -5:30 hrs of date and time.

Using Groovy Scripts to read the date and time and reduce -5:30 hrs of date and time.

Read the input value in property name -ActivityStartDate

Example:

Below Script can use the inside Mapping of groovy script.

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

import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;

import java.text.SimpleDateFormat;

import java.util.TimeZone;

import java.time.LocalDateTime;

import java.time.format.DateTimeFormatter;

def String customFunc(String arg1)

{

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");

def currentTime= arg1;

LocalDateTime datetime = LocalDateTime.parse(currentTime,formatter);

datetime=datetime.minusHours(5).minusMinutes(30);

return datetime;

}

                                                                     (OR)

Below Script can use the inside iflows of groovy script.

import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;

import java.text.SimpleDateFormat;

import java.util.TimeZone;

import java.time.LocalDateTime;

import java.time.format.DateTimeFormatter;

def Message processData(Message message) {

//Body

def body = message.getBody();

//Properties

map = message.getProperties();

value = map.get("ActivityStartDate");

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");

def currentTime= value;

LocalDateTime datetime = LocalDateTime.parse(currentTime,formatter);

datetime=datetime.minusHours(5).minusMinutes(30);

message.setProperty("CurrentDate",datetime);

return message;

}

Input:

3:00 PM 09-04-2022

3:00 AM 09-04-2022

Output:

9:30 AM 09-04-2022

9:30 PM 08-04-2022

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...