English
Groovy Code Example
About 325 wordsAbout 1 min
2026-01-09
Data Integration Connector Object API - Batch Query ERP Object Data by Time
/**
* Connector Object API - Batch Query ERP Object Data by Time
* Items marked with 'todo' require user modification/implementation
* Must first set parameters in top-right corner (Map type syncArg)
**/
String errorCodeKey = "code" // Error code field name - must match connector configuration's error code field
String successCode = "0" // Success response code - must match connector configuration's success code
String errorMessageKey = "message" // Error message field name - must match connector configuration's error msg field
String dataKey = "data" // Data field name - must match connector configuration's data field
String totalKey = "totalNum" // Total record count field name
String dataListKey = "dataList" // Data detail list field name
Map objectData = syncArg["objectData"] as Map
def apiName = objectData["objAPIName"] // ERP object apiName e.g.: BD_MATERIAL
def startTime = objectData["startTime"] // Data change start time (Unix timestamp in milliseconds)
def endTime = objectData["endTime"] // Data change end time (Unix timestamp in milliseconds)
def includeDetail = objectData["includeDetail"] // Whether to include details
def offset = objectData["offset"] // Record offset
def limit = objectData["limit"] // Current request record count
// todo Get data
Map<String, String> headers = ["token": "xxxxxx"]
def url = "http://xxx/xxx//queryMasterBatch?objAPIName=" + apiName + "&startTime=" + startTime + "&endTime=" + endTime + "&includeDetail=" + includeDetail + "&offset=" + offset + "&limit=" + limit
def (Boolean error, HttpResult httpResult, String msg) = http.get(url, headers)
if (error) {
log.info("Error getting ERP object data by time: " + msg)
// Return error data
Map<String, Object> result = [:]
result[errorCodeKey] = "500"
result[errorMessageKey] = msg
return result
}
log.info("Get ERP object data by time, url:" + url + " response:" + httpResult)
Map<String, Object> queryDataByTimeResult = httpResult.content as Map
int totalNum = queryDataByTimeResult["data"]["totalNum"] as Integer
List<Map<String, Object>> dataList = queryDataByTimeResult["data"]["dataList"] as List
// Build object data
Map<String, Object> data = [:]
data[totalKey] = totalNum
data[dataListKey] = dataList
// Return data
Map<String, Object> result = [:]
result[errorCodeKey] = successCode
result[errorMessageKey] = ""
result[dataKey] = data
return result