{
"documentType" : "RFXDocument",
"status" : "published",
"selectAttributes" : [
"EventType",
"DocumentId",
"LastModified",
"TimeCreated",
"Status",
"InternalId",
"Active",
"NextVersion",
"Description",
"DocumentVersion",
"EventState",
"Title",
"TimeUpdated",
"IsTest",
"Owner",
"TemplateObject",
"ParentWorkspace"
],
"filterExpressions": [
{
"name" : "createdDateFrom",
"field": "TimeCreated",
"op": ">="
},
{
"name" : "createdDateTo",
"field": "TimeCreated",
"op": "<="
},
{
"name": "eventTypeInList",
"field": "EventType",
"op": "IN"
},
{
"name": "nextVersionIsNull",
"field": "NextVersion",
"op": "IS NULL",
"defaultValue": true
}
]
}
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
//Properties
def properties = message.getProperties();
def last_days = properties.get('EventListFromLastDays') as Integer;
def today = new Date();
def createdFrom = today.minus(last_days);
def createdTo = today.next();
allFilters = String.format("{\"createdDateFrom\":\"%s\", \"createdDateTo\":\"%s\",\"eventTypeInList\":[\"1\",\"2\"]}",
createdFrom.format("yyyy-MM-dd'T'HH:mm:ss'Z'"), createdTo.format("yyyy-MM-dd'T'HH:mm:ss'Z'"));
message.setProperty('filters', URLEncoder.encode(allFilters, 'UTF-8'));
message.setProperty("executionLog", 'Date Filters: ' + allFilters + '. ');
message.setProperty("insertedCount", 0);
//Call the API the 1st time and assing the token = 1
message.setProperty("hasPageToken", '1');
message.setProperty("firstExecution", 1);
message.setProperty("countApiCalls", 0);
return message;
}
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
//Body
def body = message.getBody();
//Headers
def headers = message.getHeaders();
//Properties
def properties = message.getProperties();
def valueInsertedCount = properties.get("insertedCount");
def executionLog = properties.get('executionLog');
executionLog = executionLog + 'Inserted events: ' + valueInsertedCount + '. ';
def messageLog = messageLogFactory.getMessageLog(message);
messageLog.addAttachmentAsString('ExecutionLog', executionLog, 'text/plain');
return message;
}
/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en/148851bf8192412cba1f9d2c17f4bd...
If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
//Properties
def properties = message.getProperties();
//get dateFilters
def pageToken = properties.get("pageToken");
def firstExecution = properties.get("firstExecution");
if (firstExecution == 1) {
pageToken = '';
message.setProperty("pageToken", pageToken);
message.setProperty("firstExecution", 0);
}
//countApiCalls
def countApiCalls = properties.get("countApiCalls");
countApiCalls = countApiCalls + 1;
message.setProperty("countApiCalls", countApiCalls);
return message;
}
/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en/148851bf8192412cba1f9d2c17f4bd...
If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.JsonSlurper;
import groovy.xml.MarkupBuilder;
def Message processData(Message message) {
//Body
def body = message.getBody();
// get results
def jsonSlurper = new JsonSlurper();
def apiResult = jsonSlurper.parse(body);
//Properties
def properties = message.getProperties();
message.setProperty("count", 0);
message.setProperty("totalResult", apiResult.Records.size);
message.setProperty("resultRecords", apiResult.Records);
//validate if there are Results
message.setProperty("hasResults", apiResult.Records.size > 0 ? '1' : '0');
def executionLog = properties.get('executionLog');
def pageToken = properties.get("pageToken");
executionLog = executionLog + 'Total Results in API-Token-' + pageToken + ': ' + apiResult.Records.size + '. ';
message.setProperty("executionLog", executionLog);
if (apiResult.PageToken) {
message.setProperty("pageToken", apiResult.PageToken);
}
else {
message.setProperty("pageToken", '');
}
return message;
}
/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en/148851bf8192412cba1f9d2c17f4bd...
If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
//Body
def body = message.getBody();
//Headers
def headers = message.getHeaders();
//Properties
def properties = message.getProperties();
//increase count
def pageToken = properties.get("pageToken");
if (pageToken == '') {
//set hasPageToken to false
message.setProperty("hasPageToken", '0');
}
else {
message.setProperty("hasPageToken", '1');
}
return message;
}
/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en/148851bf8192412cba1f9d2c17f4bd...
If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.MarkupBuilder;
def Message processData(Message message) {
//Body
def body = message.getBody();
//Headers
def headers = message.getHeaders();
//Properties
def properties = message.getProperties();
def count = properties.get("count");
def resultRecords = properties.get("resultRecords");
message.setProperty("eventId", resultRecords[count].InternalId);
//get db schema
def db_schema = properties.get('DatabaseSchemaName');
// create SQL statement
def writer = new StringWriter();
def sqlStatement = new MarkupBuilder(writer);
sqlStatement.root {
sqlStatement.SelectStatement {
sqlStatement.arb_sourcing_event(action: 'SELECT') {
sqlStatement.table(db_schema + '.ARB_SOURCING_EVENT')
sqlStatement.access {
sqlStatement.INTERNAL_ID()
}
sqlStatement.key {
sqlStatement.INTERNAL_ID(resultRecords[count].InternalId)
}
}
}
};
//set body
message.setBody(writer.toString());
return message;
}
/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en/148851bf8192412cba1f9d2c17f4bd...
If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.JsonSlurper;
def Message processData(Message message) {
//Body
def body = message.getBody();
//Headers
def headers = message.getHeaders();
//Properties
def properties = message.getProperties();
// get results
def jsonSlurper = new JsonSlurper();
def dbResult = jsonSlurper.parse(body);
def hasResults = '0';
if (dbResult && dbResult.SelectStatement_response && dbResult.SelectStatement_response.row) {
hasResults = '1';
}
message.setProperty("hasResults", hasResults);
return message;
}
/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en/148851bf8192412cba1f9d2c17f4bd...
If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.MarkupBuilder;
def Message processData(Message message) {
//Body
def body = message.getBody();
//Headers
def headers = message.getHeaders();
//Properties
def properties = message.getProperties();
//incrementar contador
def resultRecords = properties.get("resultRecords");
def valueCount = properties.get("count");
def rfxEvent = resultRecords[valueCount];
//count insertion
def valueInsertedCount = properties.get("insertedCount");
valueInsertedCount = valueInsertedCount + 1;
message.setProperty("insertedCount", valueInsertedCount);
// create SQL statement
def writer = new StringWriter();
def sqlStatement = new MarkupBuilder(writer);
def db_schema = properties.get('DatabaseSchemaName');
//eventState:
// - PendingSelectionState -> 6
// - ClosedState -> 7
// - CancelledState -> 8
def extensionState = 'DRAFT';
if (rfxEvent.EventState == 6) {
extensionState = 'READY';
}
else if (rfxEvent.EventState == 7) {
extensionState = 'CLOSED';
}
else if (rfxEvent.EventState == 😎 {
extensionState = 'CANCELLED';
}
sqlStatement.root {
sqlStatement.InsertStatement {
sqlStatement.arb_sourcing_event(action: 'INSERT') {
sqlStatement.table(db_schema + '.ARB_SOURCING_EVENT')
sqlStatement.access {
sqlStatement.INTERNAL_ID(rfxEvent.InternalId)
sqlStatement.TITLE(rfxEvent.Title)
sqlStatement.STATUS(rfxEvent.Status)
sqlStatement.EVENT_STATE(rfxEvent.EventState)
sqlStatement.DESCRIPTION(rfxEvent.Description)
sqlStatement.EVENT_TYPE(rfxEvent.EventType)
if (rfxEvent.DocumentId) {
sqlStatement.DOCUMENT_ID(rfxEvent.DocumentId.InternalId)
}
if (rfxEvent.Owner) {
sqlStatement.OWNER_NAME(rfxEvent.Owner.Name)
}
sqlStatement.IS_TEST(rfxEvent.IsTest)
sqlStatement.ACTIVE(rfxEvent.Active)
sqlStatement.TIME_UPDATED(rfxEvent.TimeUpdated)
sqlStatement.LAST_MODIFIED(rfxEvent.LastModified)
sqlStatement.TIME_CREATED(rfxEvent.TimeCreated)
sqlStatement.CREATEDAT((new Date()).format( 'yyyy-MM-dd HH:mm:ss' ))
sqlStatement.CREATEDBY(properties.get('ExtensionUser'))
sqlStatement.EXTENSION_STATE(extensionState)
sqlStatement.HAS_TEMPLATE_OBJECT(rfxEvent.TemplateObject != null)
}
}
}
};
message.setBody(writer.toString());
return message;
}
/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en/148851bf8192412cba1f9d2c17f4bd...
If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
//Body
def body = message.getBody();
//Headers
def headers = message.getHeaders();
//Properties
def properties = message.getProperties();
//incrementar contador
valueCount = properties.get("count");
valueCount = valueCount + 1;
message.setProperty("count", valueCount);
return message;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |