E9.2 Groovy: Script Generating Null Exception Error

astradyneuk

Member
I am trying to write a Custom Groovy script to read through the output from a Data Request and produce a list of entries for inclusion in the body of an email. When testing the script within the Orchestrator Studio using the output from the Data Request everything works fine and I get the result I expect. However, if I try to run the script using Orchestrator Client I get the error "Cannot get property 'rowset' on null object" which implies the data set is not being passed through in the Orchestration, but the output from the Data Request step is mapped against the input for the Groovy script.

Has anybody come across this sort of behaviour before? I'm fairly new to Orchestrator and Groovy so may be doing something totally stupid, but do have 35 years of coding experience so not a total novice.

Thanks
Jonathan
 

eewon

Active Member
Hi Jonathan

Have you checked to see what data is actually being passed into your Groovy script? You may well find that it's not in the format that you're expecting. It's probably best to dump your input data to the log and then see what information you're getting in.

I did a similar exercise recently to process data from a Data Request which uses a Group By and this is the data that I was receiving:

JSON:
{
    "ds_F4211": {
        "output": [
            {
                "groupBy": {
                    "F4211.KCOO": "00001",
                    "F4211.DOCO": 18072,
                    "F4211.DCTO": "ST"
                },
                "COUNT": 1
            },
            {
                "groupBy": {
                    "F4211.KCOO": "00001",
                    "F4211.DOCO": 18075,
                    "F4211.DCTO": "ST"
                },
                "COUNT": 4
            },
            {
                "groupBy": {
                    "F4211.KCOO": "00001",
                    "F4211.DOCO": 18087,
                    "F4211.DCTO": "ST"
                },
                "COUNT": 4
            },
            {
                "groupBy": {
                    "F4211.KCOO": "00001",
                    "F4211.DOCO": 18090,
                    "F4211.DCTO": "ST"
                },
                "COUNT": 1
            }
        ]
    }
}

Here's the code to process this data, which returns the order information to a data set variable. Normally you wouldn't need to do this as the Data Request can return a data set variable, but there was a bug in the tools release which means that the data wasn't formatted correctly when using a Group By.

Code:
import com.oracle.e1.common.OrchestrationAttributes;
import groovy.json.JsonSlurper;
import groovy.json.JsonOutput;

HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
  HashMap<String, Object> returnMap = new HashMap<String, Object>();
 
  def inputData = new JsonSlurper().parseText(inputMap.get("dataRequest"));
  def inputOrders = inputData.ds_F4211.output;
 
  //orchAttr.writeDebug("Data request = " + inputData);
 
  def outputOrders = new ArrayList();
  for (int i = 0; i < inputOrders.size(); i++) {
      def salesOrderNumber  = inputOrders[i].groupBy."F4211.DOCO";
      def salesOrderType    = inputOrders[i].groupBy."F4211.DCTO";
      def salesOrderCompany = inputOrders[i].groupBy."F4211.KCOO";
      
      def order = new HashMap();
      order.put("salesOrderNumber",salesOrderNumber);
      order.put("salesOrderType",salesOrderType);
      order.put("salesOrderCompany",salesOrderCompany);
      
      outputOrders.add(order);
  }
 
  returnMap.put("salesOrders", JsonOutput.toJson(outputOrders));

  return returnMap;
}

Let me know if that helps.

Dave
 

astradyneuk

Member
Hi Dave

Thanks for that, I'll give it a go. I'm pretty sure the data is correct as to test it I output the result from the data request on its own and then used that as the input for testing the script on its own.

Cheers
Jonathan
 

Dave Azouth

Member
Hi Jonathan,

If you are working with TR 9.2.4. and newer create an orchestrator with the data request and activate the raw output. The Orchestrator Studio hide some tags of the Json so when you try to use it in a groovy the path is incorrect.

Groovy Input variable Data (gets the output of the previous step)
def jsonIn = new JsonSlurper().parseText(inputMap.get("Data"));
def jsonData = jsonIn.fs_DATABROWSE_F4111.data.gridData.rowset; // it could be something like this

Hope it helps

David
 
Call Orchestrations From Excel – The Easy Way to Make the Orchestrator Work for You.
Top