E9.2 Passing Dataset from Data Request to Groovy

malam28269

Member
I am able to pull JSON dataset out of Data Request but I want to pass that data to the next step (Custom function) Groovy, may someone please help to provide a simple groovy code just to print (echo) the data of the previous step once I get the data in Groovy step I will figure out how to manipulate that data. by the way I am using E1 9.2.5
Thanks,
 
I would pass in the output from your data request and then use JsonSlurper to convert the json into groovy object that you can manipulate. Here is an example that takes the json passed in to a Custom Request to a Groovy Object, and then converts the Groovy Object back to json.

import groovy.json.JsonSlurper;
import groovy.json.JsonBuilder;
import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
HashMap<String, Object> returnMap = new HashMap<String, Object>();

// convert the json into a Groovy object
def jsonIn = new JsonSlurper().parseText(inputMap.get("Input"));

// convert the Groovy object back to json
def jsonOut = new JsonBuilder(jsonIn).toString();

returnMap.put("Output", jsonOut);

return returnMap;
}
 
Hi! Is possible work with array JSON to get some Values ?

for example
Loop through an array and for each block get same values and insert those recovered values into a P55xxxx forms in 2 different registers

{
"Test1": [
{
"name": "Jhon",
"city": "New York",
},
{
"name": "William"
"city": "Detroit",
}
]
}
 
Yes, JSON array into a detail grid. In too-simple checklist form (this will take experiential learning, trial and error on your part no matter what). But here's a pattern that has worked for me multiple times. In my case I'm taking an array of data from a REST endpoint (JSON), and inserting that array into detail grid in JDE, with 1 step and no iteration.

  1. Use "record a process" to create a Form Service Request where you get into a detail grid, and populate 1 row of the grid.
  2. "Clean up" the form service request eliminating duplicate button presses and the like, de-variable grid row selections (hardcode to 1, because you're using QBE/filtering to limit your selection to 1 right? right?), remove most if not all default values, and simplify input var names.
  3. Go to the "Manage" menu on the form service request, and select "Create Orchestration". Rename the resulting orchestration according to your naming convention and save. Do not touch anything! (This is my experience, remember. Others smarter than me probably do mess with things at this point)
  4. This orchestration is your "inner" orch that populates an grid with 1 or more lines of information.
  5. Create a new "outer" orch that calls your rest endpoint, returns the entire rest response to a scripting step, and then that scripting step translates FROM the rest API endpoint format TO your "inner orch" format.
  6. To see your "inner orch" format, add it to your "outer orch", go to Transformations", and select "View Example Input"
  7. Plug your API response format and your "inner orch" format into ChatGPT and have it write you a translation script in the language of your choice (hint, Jython works GREAT for REST translation)
  8. Translate the ChatGPT script into Orchestrator's scripting format, test with your input, and when you're done plug it into your outer orch.
  9. Make sure your "inner" orch is set in the transformations screen to "Use Object for Input". That exposes a "jde__object" variable. Populate ONLY that variable with the output from your previous scripting step, and ignore any and all other mapping.
1708455672406.png
Final step, run, see it all work beautifully (and this method performs well)

SIMPLE. :LOL:
 
Last edited:
Hi! Is possible work with array JSON to get some Values ?

for example
Loop through an array and for each block get same values and insert those recovered values into a P55xxxx forms in 2 different registers

{
"Test1": [
{
"name": "Jhon",
"city": "New York",
},
{
"name": "William"
"city": "Detroit",
}
]
}
Hi Lennon,

I modified the example JSON to make it a bit easier to demo:
[
{
"test": {
"testname": "Test1",
"name": "John",
"city": "New York"
}
},
{
"test": {
"testname": "Test2",
"name": "William",
"city": "Detroit"
}
}
]

I created a JRuby script with these Inputs/Outputs:
1709305789902.png

And this script:
Ruby:
require 'json'

def main(orchAttr, inputMap)
    
    returnMap = {}
    
    # initialise variables in condition
    name =""
    city = ""
    
    # Get input from input map
    input = inputMap["input"]


    # convert input to JSON object
    jsonIn = JSON.parse(input)
    
    # initialise object index pointer
    loopcount = 0
    
    # iterate through JSON nodes
    jsonIn.each do |test|
        
        # check for nodes by name
        if jsonIn[loopcount]["test"]["testname"] == "Test1"
            # extract valuesfrom this node
            name = jsonIn[loopcount]["test"]["name"].to_s
            city = jsonIn[loopcount]["test"]["city"].to_s
        end     

        # increment index pointer
        loopcount = loopcount  + 1
    end
    
    returnMap["name"] = name
    returnMap["city"] = city
 
  return returnMap
 end


I hope that's helpful.

If you wanted all the data you could insert into an array and then map the array to a Data Set variable.

8-]
 
Last edited:
Hi Lennon,

I modified the example JSON to make it a bit easier to demo:
[
{
"test": {
"testname": "Test1",
"name": "John",
"city": "New York"
}
},
{
"test": {
"testname": "Test2",
"name": "William",
"city": "Detroit"
}
}
]

I created a JRuby script with these Inputs/Outputs:
View attachment 20092

And this script:
Ruby:
require 'json'

def main(orchAttr, inputMap)
   
    returnMap = {}
   
    # initialise variables in condition
    name =""
    city = ""
   
    # Get input from input map
    input = inputMap["input"]


    # convert input to JSON object
    jsonIn = JSON.parse(input)
   
    # initialise object index pointer
    loopcount = 0
   
    # iterate through JSON nodes
    jsonIn.each do |test|
       
        # check for nodes by name
        if jsonIn[loopcount]["test"]["testname"] == "Test1"
            # extract valuesfrom this node
            name = jsonIn[loopcount]["test"]["name"].to_s
            city = jsonIn[loopcount]["test"]["city"].to_s
        end    

        # increment index pointer
        loopcount = loopcount  + 1
    end
   
    returnMap["name"] = name
    returnMap["city"] = city
 
  return returnMap
 end


I hope that's helpful.

If you wanted all the data you could insert into an array and then map the array to a Data Set variable.

8-]
Thank you so much for the response and your time .
I'll take a look .
 
Yes, JSON array into a detail grid. In too-simple checklist form (this will take experiential learning, trial and error on your part no matter what). But here's a pattern that has worked for me multiple times. In my case I'm taking an array of data from a REST endpoint (JSON), and inserting that array into detail grid in JDE, with 1 step and no iteration.

  1. Use "record a process" to create a Form Service Request where you get into a detail grid, and populate 1 row of the grid.
  2. "Clean up" the form service request eliminating duplicate button presses and the like, de-variable grid row selections (hardcode to 1, because you're using QBE/filtering to limit your selection to 1 right? right?), remove most if not all default values, and simplify input var names.
  3. Go to the "Manage" menu on the form service request, and select "Create Orchestration". Rename the resulting orchestration according to your naming convention and save. Do not touch anything! (This is my experience, remember. Others smarter than me probably do mess with things at this point)
  4. This orchestration is your "inner" orch that populates an grid with 1 or more lines of information.
  5. Create a new "outer" orch that calls your rest endpoint, returns the entire rest response to a scripting step, and then that scripting step translates FROM the rest API endpoint format TO your "inner orch" format.
  6. To see your "inner orch" format, add it to your "outer orch", go to Transformations", and select "View Example Input"
  7. Plug your API response format and your "inner orch" format into ChatGPT and have it write you a translation script in the language of your choice (hint, Jython works GREAT for REST translation)
  8. Translate the ChatGPT script into Orchestrator's scripting format, test with your input, and when you're done plug it into your outer orch.
  9. Make sure your "inner" orch is set in the transformations screen to "Use Object for Input". That exposes a "jde__object" variable. Populate ONLY that variable with the output from your previous scripting step, and ignore any and all other mapping.
View attachment 20074
Final step, run, see it all work beautifully (and this method performs well)

SIMPLE. :LOL:
Hi dave , I understand the point .I need to improve JRUBY Scripting
Thank you so much for the response and your time.
 
ChatGPT4 is your friend for scripting! It annotates and comments code, and explains clearly what it is doing. Perfect for improving.
 
Back
Top