It is the groovy script written for using the script in SAP Cloud platform integration interface flow.
Have written a Groovy script to minus 10 minutes from current time and different stored format time. This it required in building the query.
Input: LastSuccessfulRun_Query = "04/14/2021 16:20:00"
Groovy Script:
import com.sap.gateway.ip.core.customdev.util.Message;import java.util.HashMap;
import java.util.TimeZone;
import groovy.time.TimeCategory;
def Message processData(Message message) {
//Body
def body = message.getBody();
//Properties
def curDateTime1 = "";
def before10mins = "";
def bef10mins = "";
def lastrun = "";
def value1 = "";
def tz = TimeZone.getTimeZone("UTC")
def ts = new Date()
map = message.getProperties();
value = map.get("LastSuccessfulRun_Query");
use( TimeCategory ) {
before10mins = ts - 10.minutes
lastrun = new Date(value) - 10.minutes
}
curDateTime1 = (ts.format("MM/dd/yyyy HH:mm:ss", timezone=tz))
bef10mins = (before10mins.format("MM/dd/yyyy HH:mm:ss", timezone=tz))
value1 = (lastrun.format("MM/dd/yyyy HH:mm:ss", timezone=tz))
def datequery = "(CREG_PROD_LAST_CHANGE_DATE_TIME ge"+"'"+lastrun+" UTC"+"'"+" and CREG_PROD_LAST_CHANGE_DATE_TIME le"+"'"+bef10mins+" UTC"+"'"+")";
// def datequery = "(CREG_PROD_LAST_CHANGE_DATE_TIME ge'01/15/2021 00:00:00 CET' and CREG_PROD_LAST_CHANGE_DATE_TIME le'01/20/2021 00:00:00 CET')";
message.setHeader("datequery",datequery);
message.setProperty("CurrentDate",curDateTime1);
message.setProperty("before10mins",before10mins);
message.setProperty("bef10mins",bef10mins);
message.setProperty("value",value);
message.setProperty("value1",value1);
message.setProperty("lastrun",lastrun);
return message;
}
Output: value1 = "04/14/2021 16:10:00"
No comments:
Post a Comment