E9.2 Converting JRuby to Groovy

JohnDanter2

JohnDanter2

VIP Member
Hi folks

Me and my resident OO language geek have written a simple manipulate output script to show a user defiened orchestration output variable as a response (RRDResult) and also a clever way of setting all the Object Line Error info into another variable RRDErrorText'

However we wrote this JRuby but I would like to convert it Groovy. Camn someone help us please?

Code:
require 'json' 
def main(orchAttr, input)
   
    jsonIn = JSON.parse(input)
   
    
    #Default reponse to be OK
   jsonIn['RRDResult']='200001'
    #if error detected set to 200003    
   if jsonIn['continuedOnError']
       #set the control variable RRDResult to be in error state
        jsonIn['RRDResult']='200003'
       jsonIn['RRDErrorText']=
           'O: '+jsonIn['ServiceRequest1']['fileName']+' L: '+jsonIn['ServiceRequest1']['lineNumber'].to_s+' E: '+jsonIn['ServiceRequest1']['szerror']+' '+jsonIn['ServiceRequest1']['glossaryText']
    end
   
     #if jsonIn['jde__status']=='WARN'
   #if 1==1
    # jsonIn['RRDResult2']=jsonIn['jde__status']
   #end
   
   
      #Add code here to manipulate JSON output
   # jsonIn['szSourceResultField']=200003;
   
   #This bit of code can assign 200003 to the output variable if the inpit variable is not present
   # and this will occur if the BSFN ended in error as NO outputs will be present normally
    if !jsonIn['szSourceResultField']
      jsonIn['szSourceResultField']=200003;
    end;
   
   # jsonIn['szUserReservedReference']=jsonIn['RRD_N55APIRD_ORCH.szUserReservedReferenceVO'];
      
   #input['RRD_N55APIRD_ORCH.szUserReservedReferenceVO'] 
   
       # jsonIn=input.toString();
  #  if (jsonIn.continuedOnError) [jsonIn['MyResultVO']=200003]
   
    jsonOut = JSON.generate(jsonIn)
   
    return jsonOut
end

"RRDResult": "200003",
"RRDErrorText": "O: n55apird.c L: 501 E: 616V CAUSE...Auto Batch Receipts could not be created through the Auto Bank Statement Process (R09616)\n\nRESOLUTION...Review the bank statement for details.\n\n",


Thanks


John
 
Last edited:
He's a genius

So what this code does is look for continuedOnError (BSFN step much have this ticked in error handling) then grabs the message and builds a new string called RRDErrorText which summarises the Object throwing the error, the line #, the error code and the error text all in one nice output line :)

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'
       jsonIn.RRDErrorText =
           'O: '+jsonIn.ServiceRequest1.fileName+' L: '+jsonIn.ServiceRequest1.lineNumber+' E: '+jsonIn.ServiceRequest1.szerror +' '+jsonIn.ServiceRequest1.glossaryText
   }
  
    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;
}
 
It turns all of this

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 2 lines such as this


Code:
"scsResult": "200003",
    "scsInfo": "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",

So this is now great for small mobile devices with a relatively small screen size.
And the good news is if there is no error scsResult = 200001 and scsInfo isn't part of the output :)

Groovy is pretty cool and will help me if there ever IS an error. As now I will know the BSFN object, the Line ID, the error code and the text
 
This is aweseome! Just curious, what Http response does the API give in this case? Is it a 200 or a 500?

Thanks,
Dave
 
I think it's always 200 unless there is some major exzception like a token or server issue

I've told .NEt team to look for jde__status to see what that is. As again I think if there no errors its SUCCESS on an error or warning like a UDC not found it's WARN. Not sure what it is when the transaction is really upset lol

I've written my own NER which I can call in various modes that throws various errors, record locks, NER errors and Retirn code errors. So it's a learning excercise to see how REST handles it all

Thanks again for help the other day Dave
 
Also you may have spotted I changed RRDResult to scsResult lol

And I found out that you dont' need to declare the variabel anywhere but in the manipluate output script.
It just makes it for you :)

So this is just a copy and paste into ALL my orchestrations going forward to help us have a simplified error output.
I should probably change the topic of this post lol
 
Back
Top