dtujo2022
Member
So I have gotten the hang of create custom formatted json within a Groovy script, but what I am struggling with is returning the Json in the orchestration as the object and not a string.
Here is what I have:
This is what it returns:
UPDATE- I had to add "def jsonOutput = JsonOutput.toJson(output)"
This got it working.
Here is what I have:
Java:
import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
import groovy.json.*
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
HashMap<String, Object> returnMap = new HashMap<String, Object>();
def inputData = (String)inputMap.get("serialData")
def jsonSlurper = new JsonSlurper();
def datajson = jsonSlurper.parseText(inputData);
def workOrders = datajson.fs_DATABROWSE_V553112N.data.gridData.rowset;
def output = [
"LoadNumber": (String) inputMap.get("LoadNumber"),
"WorkOrders": []
]
def workOrderMap = [:]
workOrders.each { row ->
def woKey = row.F553112L_DOCO
def opKey = row.F5548S1_OPSQ
if(!workOrderMap.containsKey(woKey)) {
workOrderMap[woKey] = [
"WONumber": row.F553112L_DOCO,
"WOType": row.F553112L_DCTO,
"WOOperations": []
]
}
def workOrder = workOrderMap[woKey]
def operation = workOrder.WOOperations.find {it.OperationSequence == opKey}
if(!operation){
operation = [
"OperationSequence": row.F5548S1_OPSQ,
"OperationCode": row.F553112L_Y55OP,
"Serials": []
]
workOrder.WOOperations << operation
}
operation.Serials << ["SerialNumber": row.F5548S1_LOTN]
}
output.WorkOrders = workOrderMap.values().toList()
returnMap.put("jsonout", output);
return returnMap;
}
This is what it returns:
UPDATE- I had to add "def jsonOutput = JsonOutput.toJson(output)"
This got it working.
Last edited: