E9.2 Connector Status

Stank1964

Well Known Member
I have an outbound orchestration and I need to try the connector and if it fails, I need to get a fresh token and make the request again. Can someone tell me how to access the "statusCode" or even the "status" variables in the response? Here is the response.

{
"message": {
"ServiceRequest: 55CN_SalesForceCase_Connector": {
"statusCode": 401,
"error": "java.lang.Exception: External Generic Call Failed See Log For Details: 401 ",
"headers": {}
}
},
"exception": "Exception",
"timeStamp": "2023-05-15T12:20:53.924-0400",
"userDefinedErrorText": "",
"status": "ERROR",
"jde__simpleMessage": "55CN_SalesForceCase_Connector failed: java.lang.Exception: External Generic Call Failed See Log For Details: 401",
"jde__status": "ERROR",
"jde__startTimestamp": "2023-05-15T12:20:53.293-0400",
"jde__endTimestamp": "2023-05-15T12:20:53.924-0400",
"jde__serverExecutionSeconds": 0.631
}
 
Under Transformations of the connector you return raw output, that should get you the entire response. Then you feed that response into scripting component, and if it's groovy you use jsonslurper to parse the entire json, and pick out the "address" of the statusCode. Set that as an output of your script, and then you can test using a rule whether it's 200/401/etc or not.
 
I think it does help to start with a strong basic training. I've said it in other threads and at conference last week, I can personally vouch for ACBM Solutions's training.

It helps to have community to bounce ideas off of, so you're in a great spot for that!

Google skill is great for groovy scripts, and I've started being able to recommend chatGPT skills as well-- chatGPT4 can write a mean groovy script based on input you give it.

Last but not least, it takes some time to build up a repertoire of "oh this isn't working, oh I need to go look over here". It's technically in documentation but the synthesis of using a documented feature in conjunction with a problem you're running into takes time to build up.

It's well worth it! You're building current-gen APIs on a beautiful low code platform. Many companies pay 100's of thousands of dollars on top of ERP to do the same thing on 3rd party integration software..
 
Larry at ACBM trained me and I highly recommend his class. One of the best real world classes I've taken ever. It will cover the bases in a complete way, but groovy is very different and changes everything.
 
Here's the final message of a chatGPT4 session where I put in a JSON as input and asked it to write me a groovy script to parse out all of the inputs programmatically. Get going on chatGpt skillbuilding to skip right over the drudge of piecing together a script from 5-6 stackoverflow articles.

Yes, you can programmatically find the arrays within your input JSON and list the fields within each array using Groovy. To do this, you can parse the JSON and then loop through the keys to find arrays. Once you find an array, you can loop through its elements and print the fields within each element.

Here's an example using Groovy's `JsonSlurper` to parse the JSON and then find arrays and their fields:

```groovy
import groovy.json.JsonSlurper

String inputJson = '''
{
"cActionCode": "string",
"mnUniqueKeyID": "string",
"People": [
{
"cPersonLineActionCode": "string",
"mnPersonUniqueKeyID": "string",
"mnPersonID": "string",
"szPersonName": "string"
}
],
"Costs": [
{
"cCostActionCode": "string",
"mnCostUniqueKeyID": "string",
"jdIncidentCostDate": "string"
}
]
}
'''

def parsedJson = new JsonSlurper().parseText(inputJson)

parsedJson.each { key, value ->
if (value instanceof List) {
println "Array found: $key"
value.eachWithIndex { element, index ->
println "Element $index fields:"
element.each { fieldKey, fieldValue ->
println " $fieldKey"
}
}
}
}
```

This script will output:

```
Array found: People
Element 0 fields:
cPersonLineActionCode
mnPersonUniqueKeyID
mnPersonID
szPersonName
Array found: Costs
Element 0 fields:
cCostActionCode
mnCostUniqueKeyID
jdIncidentCostDate
```

You can replace the `inputJson` variable with your input JSON string. The script will loop through the keys in the JSON and find arrays, then loop through each element of the array and print its fields.
 
Hey Dave. Thanks for the encouragement and input to this great resource. I was able to stick to it and get my data request response formatted to produce the REST call body, I feel like it's a miracle. You do need to specify the "return raw data" on the transformations of the data request.

Here's the groovy. Basically, this reads the json output from a data request specifically focusing on the array of records. It reformats the array into a new array that is the basis for the rest API call. I think that this script is a good foundation on how to traverse a string which is formatted as json and manipulate it into an entirely new json string output. I gotta give a shout out to you Dave and Oracle document 2667935.1 for the guidance. Good stuff.

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>();

//Input is the full output of the data request
String inSalesForceOrderNo = (String)inputMap.get("inSalesForceOrderNo");
String inDataSet = (String)inputMap.get("inDataSet");

//create an object out of it
def jsonSlurper = new JsonSlurper();
def jsonObject = jsonSlurper.parseText(inDataSet);

//get the record set
def dataset = jsonObject.fs_DATABROWSE_V55SR01J.data.gridData.rowset;

//create the output array and attributes array
def outDataSet = [];
def attributes = [type: 'Defect__c']

for(def item : dataset) {

String strProd = item.F55SR01H_PRODF
String strPoint = item.F55SR01D_PRODM
String strDefect = item.F55SR01D_FAILCD

//create a new object for the resulting data set with the new date values
def newArray = [:]
newArray.attributes = attributes;
newArray.Case__C = inSalesForceOrderNo;
newArray.Product_Type__c = strProd;
newArray.Point_Of_View__c = strPoint;
newArray.ID_Defect__c = strDefect;


//add to new output array
outDataSet.push(newArray);
}

//create a json string from the new data set and return the data
String outDataSetJson = JsonOutput.toJson(outDataSet);

returnMap.put("outDataSet", outDataSetJson);
return returnMap;
}
 
Yay I love it!! Thanks for sharing the resulting script, it will help many more people for sure
 
When it comes to the connector, we can have 3 things happen: the API works, the API throws an error or the connector fails and the API isn't called at all, perhaps there was a communications issue or an authentication problem. Anyway, I would hope that the response from the connector call, regardless of which of these 3 scenarios happen would be included as part of the raw output of the connector. That does not seem to be the case for me. If the connector fails and never calls the API, it seems like the raw output is not populated. Might anyone have a clue about this?
 

Similar threads

Back
Top