E9.2 Convert space seperated string to run in loop for Form Request

khaleesi

Member
Hi there,
I am a form request which runs in a loop over multiple orchestration inputs. The orchestration inputs are in array format which requires end users to add input one by one in columnar format.
However if users have more than 10 inputs, its a hassle for them to add those many lines.
So, to resolve this, I created a groovy script which takes input in form of space separated string and pass it as dataset to the form request.

My groovy script is like below

import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
import groovy.json.JsonSlurper;
import groovy.json.JsonBuilder;
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
HashMap<String, Object> returnMap = new HashMap<String, Object>();
// Add logic here
String stringVal = (String)inputMap.get("myString")
values = stringVal.split(' ')

def dataset =[]

// Loop through each value and add it to the dataset
values.each { value ->
// Add an object with a single field "value" to the dataset
dataset << [Shipment: value]

}
def ShipmentsDataset = JsonOutput.toJson(dataset)

returnMap.put(ShipmentsDataset)
return returnMap
}

It gives exception error "Exception groovy.lang.MissingPropertyException: No such property: JsonOutput for class: Script102".

1720726866503.png

Any help in resolving this error is greatly appreciated.
Thanks,
Gauri.
Release 23
 
Hi,

There are a couple of issues to get this to work.

1. import groovy.json.JsonOutput.
2) change returnMap.put(ShipmentsDataset) to returnMap.put("ShipmentsDataset",ShipmentsDataset)

Kevin
 
Besides what Kevin said, add ShipomentsDataset to Output and Variable Name.
 
That worked beautifully, Thank you Alfred and Kevin.

Quick question, which site/material did you refer to learn more about Groovy scripting specifically for JDE orchestrator.

Thanks,
Gauri.
 
Surely there are a lot of course in youtube, udemy, coursera, etc. But in my opinion it's not necessary if you know development. If you have a specific question chatgpt is your friend :) In fact, we don't need more than variable, condicional, loop and works with json. Furthermore, in the new tools groovy is obsoleted (but you can install with a package), the official/standard language or oracle is bettings is JRuby.

Regards.
 
I will be giving a session at InFocus in Denver on using ChatGPT with orchestrator-- it's an expanded version of what I've been preaching here.
 
Back
Top