# Groovy Script for JDE Orchestrator: Custom Request Generator

> Source: https://netray.co/tools/jde-orchestrator-groovy-custom-request-script-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Generate a Groovy custom service request for JD Edwards Orchestrator that reads delimited text from an input, returns it as an array of rows and logs to the AIS Server log.

## Category

developer

## Erp

JD Edwards EnterpriseOne

## Audience

- JDE developer
- Orchestrator developer

## Tool

**Kind:** template

**Output:** code

**Language:** groovy

**Fields:**

#### Script purpose

**Key:** purpose

**Type:** text

**Default:** Split uploaded CSV text into rows for an iteration over Sales Order Entry

#### Input name: delimited text

**Key:** in_text

**Type:** text

**Default:** csvText

#### Input name: delimiter

**Key:** in_delim

**Type:** text

**Default:** delimiter

#### Array output name

**Key:** out

**Type:** text

**Default:** rows

#### Log message prefix

**Key:** prefix

**Type:** text

**Default:** CSV_SPLIT:

**Blocks:**

#### Custom service request (Groovy)

**Body:** import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;

// Purpose: {{purpose}}
// Inputs: {{in_text}} (text with a header line), {{in_delim}} (single character, default comma)
// Outputs: {{out}} (array of rows keyed by header names), RowCount
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
  HashMap<String, Object> returnMap = new HashMap<String, Object>();

  String csvText = (String) inputMap.get("{{in_text}}");
  String delimiter = (String) inputMap.get("{{in_delim}}");
  if (delimiter == null || delimiter.isEmpty()) {
    delimiter = ",";
  }

  List<HashMap<String, Object>> rows = new ArrayList<HashMap<String, Object>>();
  if (csvText == null || csvText.trim().isEmpty()) {
    orchAttr.writeWarn("{{prefix}} no input text received");
    returnMap.put("{{out}}", rows);
    returnMap.put("RowCount", "0");
    return returnMap;
  }

  List<String> lines = csvText.readLines();
  String[] headers = lines.get(0).split(java.util.regex.Pattern.quote(delimiter), -1);

  for (int i = 1; i < lines.size(); i++) {
    String line = lines.get(i);
    if (line.trim().isEmpty()) {
      continue;
    }
    String[] cells = line.split(java.util.regex.Pattern.quote(delimiter), -1);
    HashMap<String, Object> row = new HashMap<String, Object>();
    for (int c = 0; c < headers.length; c++) {
      row.put(headers[c].trim(), c < cells.length ? cells[c].trim() : "");
    }
    rows.add(row);
  }

  orchAttr.writeDebug("{{prefix}} parsed " + rows.size() + " rows");
  returnMap.put("{{out}}", rows);
  returnMap.put("RowCount", String.valueOf(rows.size()));
  return returnMap;
}

#### Test input for Orchestrator Studio

**Body:** {{in_text}}:
Customer,Branch,Item,Quantity
4242,30,220,10
4243,30,240,5

{{in_delim}}:
,

**Notes:** Keep the main(OrchestrationAttributes orchAttr, HashMap inputMap) signature and the returnMap exactly as the Studio template defines them; only the body changes. Returning a list of maps as an array output depends on your Orchestrator Studio and Tools release, so test it in the Studio test panel before mapping it into an iteration. The parser does not handle quoted fields that contain the delimiter.

## Content

**Intro:** This generator writes a Groovy custom service request for JD Edwards EnterpriseOne Orchestrator that turns delimited text into an array of rows an orchestration can iterate over. It follows the standard custom request template with orchAttr logging, for Tools 9.2 Orchestrator Studio.

**Sections:**

#### How to use it

**Body:** In Orchestrator Studio create a Custom service request, choose Groovy, and define the inputs and outputs with the same names you enter here (case matters). Paste the generated body over the template, keeping the imports you need. Map the array output into the next orchestration step, for example a form request against Sales Order Entry that runs once per row, by selecting the iterate over option on that step. Use the Test button in the custom request with the sample input to confirm the output before wiring it in.

**Bullets:**

- Inputs and outputs are defined on the request, not inside the script
- RowCount is a plain string output you can use in a rule (for example stop if 0)
- Keep each script small and single purpose so it is easy to retest after a Tools update

#### The template behind it

**Body:** Every Groovy custom request is a function main(OrchestrationAttributes orchAttr, HashMap inputMap) that returns a HashMap of outputs. Inputs arrive in inputMap by name as strings; outputs are whatever you put in returnMap. The orchAttr object gives access to orchestration context and logging: writeWarn writes a warning to the AIS Server log and writeDebug writes only when debug logging is on. Do not rename main or change its parameters, because the orchestration engine calls it by that signature. The same pattern is what people mean by an orchestrator logic extension: logic that a rule or form request cannot express, written as a small script.

#### Worked example: CSV file into sales orders

**Body:** A customer sends a weekly CSV of releases. A connector or an upload step passes the file content as csvText. This script splits it on commas, uses the first line as headers and returns rows such as {Customer: 4242, Branch: 30, Item: 220, Quantity: 10}. The next step iterates over rows and calls a form request that enters each line, so one orchestration call creates many order lines. If the file has 300 lines, keep an eye on runtime and AIS thread use; large files are better staged and processed by a UBE.

#### Common mistakes

**Body:** The most common failure is a name mismatch: the input in Studio is CSVText while the script reads csvText, so the script sees null. The second is relying on quoted CSV values; this simple parser splits on every delimiter, so either have the sender avoid embedded commas or use a tab delimiter. Third, leaving writeDebug calls inside loops writes one log line per row and floods the AIS log when debug is enabled. Finally, remember the script runs inside the AIS Server JVM: avoid file system writes and long loops.

**Cta:** If you want your team to ask JD Edwards for this kind of data in plain English, with Groovy and orchestrations as the governed back end on your own servers, we can build that.

**Faq:**

#### How do I read a CSV file in a JDE orchestration?

**Answer:** Get the file content into a string input, for example from a connector, a file transfer step or the caller's JSON, then use a Groovy custom request like this one to split it into an array output. A following step iterates over the array and runs a form or data request per row.

#### What is the Groovy function signature for a JDE custom request?

**Answer:** HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap), importing com.oracle.e1.common.OrchestrationAttributes. You read inputs with inputMap.get, put outputs into a HashMap you return, and log with orchAttr.writeWarn or orchAttr.writeDebug. Changing the signature stops the request from running.

#### Can an orchestration take array inputs?

**Answer:** Yes, orchestrations can define array inputs and outputs and a step can iterate over them, but what is available depends on your Orchestrator Studio and Tools release. Returning an array from Groovy as shown here is a common way to build that array inside the orchestration when the caller sends flat text.

#### Where do orchAttr log messages go?

**Answer:** They go to the AIS Server log. writeWarn lines appear at warning level, while writeDebug lines appear only when the AIS Server log level includes debug. Use a fixed prefix, as this generator does, so you can grep for your script's lines among the rest of the server output.

## Search terms

groovy script for jde orchestrator, jde ais groovy files, jde orchestrator logic extension, how to read csv file in jde orchestrator, jde orchestrator array inputs, jde orchestrator custom service request groovy, orchattr writedebug

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
