E9.2 Knowledge sharing: A simplified one line error ouput response :)

JohnDanter2

JohnDanter2

VIP Member
Hi all

I just thought I'd share a simple bit of Groovy which can read the output of a BSFN step and concatonate all the usual error info into one easily readable line (great for smaller mobile devices)
I create 2 new output variables RRDResult and RRDErrorText (you can call yours whatever you like)

Code:
import groovy.json.JsonSlurper;
import groovy.json.JsonBuilder;
import com.oracle.e1.common.OrchestrationAttributes;
String main(OrchestrationAttributes orchAttr, String input)
{
  def jsonIn = new JsonSlurper().parseText(input);
  // modify jsonIn;
 
     //Default reponse to be OK
     jsonIn.RRDResult = "200001"
 
 //if error detected set to 200003
   if (jsonIn.continuedOnError!=null) {
       //set the control variable RRDResult to be in error state
        jsonIn.RRDResult='200003'
        // Build error text string from object O, line number L, error code E and error text
       jsonIn.RRDErrorText =
           'O: '+jsonIn.ServiceRequest1.fileName+' L: '+jsonIn.ServiceRequest1.lineNumber+' E: '+jsonIn.ServiceRequest1.szerror +' '+jsonIn.ServiceRequest1.glossaryText
   }
 
  def jsonOut = new JsonBuilder(jsonIn).toString();
  // orchAttr.writeWarn("custom log entry - warning");
  // orchAttr.writeDebug("custom log entry - debug");
  return jsonOut;
}

So what this does is convert all this usual output stuff...
Code:
{
    "ServiceRequest1": {
        "szerror": "0027",
        "errorLevel": 1,
        "alphaDescription": "Error: User Defined Code Error",
        "glossaryText": "CAUSE . . . . The entered code was not found in the User Defined Codes.\nRESOLUTION. . Enter a valid code or place the cursor in the field in error\n              and press 'F1' to display the valid values for the field.\n",
        "fileName": "rtk_udvl.c",
        "lineNumber": 597
    },
    "continuedOnError": [
        {
            "step": "RRD_N55APIRD_BSFN",
            "message": {
                "RRD_N55APIRD_BSFN": {
                    "szerror": "0027",
                    "errorLevel": 1,
                    "alphaDescription": "Error: User Defined Code Error",
                    "glossaryText": "CAUSE . . . . The entered code was not found in the User Defined Codes.\nRESOLUTION. . Enter a valid code or place the cursor in the field in error\n              and press 'F1' to display the valid values for the field.\n",
                    "fileName": "rtk_udvl.c",
                    "lineNumber": 597
                }
            },
            "timeStamp": "2023-03-16T12:02:18.435-0500",
            "userDefinedErrorText": ""
        }
    ],

Into 1 output variable (scsInfo) when there is an error, like this

Code:
"RRDResult": "200003",
"RRDErrorText": "O: rtk_udvl.c L: 597 E: 0027 CAUSE . . . . The entered code was not found in the User Defined Codes.\nRESOLUTION. . Enter a valid code or place the cursor in the field in error\n              and press 'F1' to display the valid values for the field.\n",

This code also sets output variable RRDResult to 200001 (and the error text will not be created) when all is ok and then 200003 when any error is detected

I hope you find this useful as I will now be copy pasting this into ALL my orchestrations going forward

Thanks

John
 
Last edited:
Further Groovy after a bit of fine tuning and demos


Code:
import groovy.json.JsonSlurper;
import groovy.json.JsonBuilder;
import com.oracle.e1.common.OrchestrationAttributes;
String main(OrchestrationAttributes orchAttr, String input)
{
  def jsonIn = new JsonSlurper().parseText(input);
  // modify jsonIn;
    
     //Default reponse to be OK
     jsonIn.scsResult = "200001"
     
 //if error detected set to 200003     
   if (jsonIn.continuedOnError!=null) {
       //set the control variable scsResult to be in error state   
        jsonIn.scsResult='200003'
       // construct info variable scsInfo to be D: Error Desc + O: E1 Object + E: Error code + L: Line #
       jsonIn.scsInfo =
        'D: '+jsonIn.ServiceRequest1.alphaDescription+' O: '+jsonIn.ServiceRequest1.fileName+' E: '+jsonIn.ServiceRequest1.szerror +' L: '+jsonIn.ServiceRequest1.lineNumber         
        //  Strip out carriage returns and spaces from glossary text
       //'D: '+jsonIn.ServiceRequest1.glossaryText.replaceAll('\\n', ' ').replaceAll('[ ]+',' ')+' O: '+jsonIn.ServiceRequest1.fileName+' E: '+jsonIn.ServiceRequest1.szerror +' L: '+jsonIn.ServiceRequest1.lineNumber
   }
   
    if (!jsonIn.szSourceResultField) {
      jsonIn.szSourceResultField=200003;
    }
    
    
  def jsonOut = new JsonBuilder(jsonIn).toString();
  // orchAttr.writeWarn("custom log entry - warning");
  // orchAttr.writeDebug("custom log entry - debug");
  return jsonOut;
}
 
last tweak after realising SREQ give a slightly different output


Code:
import groovy.json.JsonSlurper;
import groovy.json.JsonBuilder;
import com.oracle.e1.common.OrchestrationAttributes;
String main(OrchestrationAttributes orchAttr, String input)
{
  def jsonIn = new JsonSlurper().parseText(input);
  // modify jsonIn;
    
     //Default reponse to be OK
     jsonIn.scsResult = "200001"
    
 //if error detected set to 200003     
   if (jsonIn.continuedOnError!=null) {
       //set the control variable scsResult to be in error state   
        jsonIn.scsResult='200003'
      
       if (jsonIn.ServiceRequest1.alphaDescription!=null) {
          //this came from a BSFN reponse
            // construct info variable scsInfo to be D: Error Desc + O: E1 Object + E: Error code + L: Line #
          
       jsonIn.scsInfo =
         'D: '+jsonIn.ServiceRequest1.alphaDescription+' '+jsonIn.ServiceRequest1.glossaryText.replaceAll('\\n', ' ').replaceAll('[ ]+',' ')+' O: '+jsonIn.ServiceRequest1.fileName+' E: '+jsonIn.ServiceRequest1.szerror +' L: '+jsonIn.ServiceRequest1.lineNumber
       }
           else
           {
               // this came from a form request so swap around start and end of continuedOnError.message
              
        jsonIn.scsInfo  = jsonIn.continuedOnError.message[0].substring(jsonIn.continuedOnError.message[0].lastIndexOf(" Title:") + 8) +  jsonIn.continuedOnError.message[0].substring(0, jsonIn.continuedOnError.message[0].lastIndexOf(" Title:"))                     
           }
      
   }
  
    //OPTIONAL code to send back szSourceResultField if there is a hard COM error and no values are returned
   // if (!jsonIn.szSourceResultField) {
   //   jsonIn.szSourceResultField=200003;
   // }
    
  def jsonOut = new JsonBuilder(jsonIn).toString();
  // orchAttr.writeWarn("custom log entry - warning");
  // orchAttr.writeDebug("custom log entry - debug");
  return jsonOut;
}
 
John -

While implementing your code, see an exception. Any help will be appreciated..

Tools Release: EnterpriseOne 9.2.5.3
Applications Release: E920

1683669587836.png

1683669403151.png
 
Hi

I can get back you on this but for now 2 things

1) my groovy is my finaly END Manipulkate output part, yours is in a custom groovy function.

2) be aware that the if (jsonIn.ServiceRequest1.alphaDescription!=null) part means step 1 in your ORCH flow, CuX0005A only

You have 2 steps, I had just one
So maybe you need 2 ifs?
if (jsonIn.ServiceRequest1.alphaDescription!=null) for CuX0005A

if (jsonIn.ServiceRequest2.alphaDescription!=null) for Test123

As the JSON outout will be made up out of how ever many blocks were execited and created output variables.
If you have 3 steps executed your output will have 3 json blocks jsonIn.ServiceRequest1 jsonIn.ServiceRequest2 jsonIn.ServiceRequest3
 
Back
Top