Custom OData Action returns JSON data as a string value
I have this action configured:
|
{ "name":"InitiateApprovalProcess", "description":"Initiate the approval process", "parameters":[ { "name":"ChangeNotice", "type":"ChangeNotice", "isNullable":false, "isCollection":false }, { "name":"CreationDate", "type":"String", "isNullable":false } ], "returnType":{ "type":"String", "isCollection":false } } |
With this JS:
|
function action_InitiateApprovalProcess(data, params) { var ChangeNoticeProcessor = Java.type("com.xyz.smb.processors.ChangeNoticeProcessor"); return ChangeNoticeProcessor.initiateApprovalProcess(data, params); } |
And this Java Code (I have removed the product details etc.):
|
public static ActionResult initiateApprovalProcess(ActionProcessorData data, Map<?, ?> parameters) { JSONObject jsonObject = new JSONObject(); jsonObject.put("SID", "SID"); jsonObject.put("RID", "RID"); jsonObject.put("DATE", "1.1.2020");
JSONArray rpArray = new JSONArray(); JSONObject rpObject = new JSONObject(); rpObject.put("CLS", "VLASS1232"); rpObject.put("POS", "PS11"); rpObject.put("NDE", "ND12"); rpObject.put("GD", "GUID1234"); rpObject.put("DESC", "DESC045"); rpObject.put("MT", "MAT345"); rpObject.put("QTY", "QTY034"); rpObject.put("UNIT", "UNOT12"); rpObject.put("BOOL", "TRUE"); rpObject.put("DR", "DRR001"); rpObject.put("DRLT", "OO"); rpArray.add(0, rpObject); jsonObject.put("DTA", rpArray);
EntityAttribute retEntity = new EntityAttribute("Edm.String", null, PropertyValueType.PRIMITIVE, jsonObject.toString()); ActionResult actionResult = new ActionResult(); actionResult.setReturnedObject(retEntity); } |
We receive the JSON output/response as a string value. We do not receive it as we would expect a JSON data format.
Expected result:
JSON response:

Actual result:
Response:
"{\"SID\":\"SID\",\"RID\":\"RID\",\"DATE\":\"1.1.2020\",\"DTA\":[{\"CLS\":\"VLASS1232\",\"POS\":\"PS11\",\"NDE\":\"ND12\",\"GD\":\"GUID1234\",\"DESC\":\"DESC045\",\"MT\":\"MAT345\",\"QTY\":\"QTY034\",\"UNIT\":\"UNOT12\",\"BOOL\":\"TRUE\",\"DR\":\"DRR001\",\"DRLT\":\"OO\"}]}"
Does anyone know how what I am doing wrong? Why I am not getting the result as a JSON data but a string?

