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

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