E9.2 Assistance with Manipulate Output

notchy

notchy

Active Member
Hoping someone could assist me with figuring this out.

I have a request to an exisiting Orchestration where I need to do a calculation to a field. I have that working in groovy but the user wants this new calculated field to be included in the json section where most of the required fields are coming from a data request from a base bsvw.

Can someone show me a sample script of how to manipulate the output to get the calculated "Total" value highlighted in yellow to move up to the preceding section ? So that when the output Json is generated it will look like my example below.

Nooby learning :)

1675367655367.png 1675367723633.png
 
Hey, can you post the text of the output JSON here so we can try things against your actual output? I think I've done something similar but am not finding it right off the bat.
 
{
"branch": "AGSP",
"lotNumber": "2025",
"location": "13",
"itemNumber": "001ZZ",
"itemDescription": "Ud,G",
"UOM": "CS",
"XREF": "C:800971",
"palletCount": 220,
"dateBestBefore": "2029-01-25",
"dateLotEffectivity": "2029-01-25",
"dateLotExpiration": "2029-01-25",
"dateOnHand": "2029-01-25",
"brand": "CONYT",
"allergens": "E",
"shelfLifeDays": 980,
"palletTrackingRequired": "Y",
"GetInventoryDetail": {
"tableId": "V41021G",
"rowset": [
{
"branch": " AGSP",
"lotNumber": "2025",
"location": "13",
"qtyOnHand": 1821,
"qtyOnPO": 0,
"qtyHardCommit": 0,
"qtyHardCommitWO": 0,
"itemNumber": "00080"
}
],
"records": 1,
"moreRecords": false
},
"Total": "1821"
}
 
Last edited:
Hey, can you post the text of the output JSON here so we can try things against your actual output? I think I've done something similar but am not finding it right off the bat.
{
"branch": "AGSP",
"lotNumber": "2025",
"location": "13",
"itemNumber": "001ZZ",
"itemDescription": "Ud,G",
"UOM": "CS",
"XREF": "C:800971",
"palletCount": 220,
"dateBestBefore": "2029-01-25",
"dateLotEffectivity": "2029-01-25",
"dateLotExpiration": "2029-01-25",
"dateOnHand": "2029-01-25",
"brand": "CONYT",
"allergens": "E",
"shelfLifeDays": 980,
"palletTrackingRequired": "Y",
"GetInventoryDetail": {
"tableId": "V41021G",
"rowset": [
{
"branch": " AGSP",
"lotNumber": "2025",
"location": "13",
"qtyOnHand": 1821,
"qtyOnPO": 0,
"qtyHardCommit": 0,
"qtyHardCommitWO": 0,
"itemNumber": "00080"
}
],
"records": 1,
"moreRecords": false
},
"Total": "1821"
}
 
Try this:
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);
  jsonIn.GetInventoryDetail.rowset[0].put("Total",jsonIn.get("Total"));
  jsonIn.remove("Total");
  // modify jsonIn;
  def jsonOut = new JsonBuilder(jsonIn).toString();
  // orchAttr.writeWarn("custom log entry - warning");
  // orchAttr.writeDebug("custom log entry - debug");
  return jsonOut;
}

This works with me structuring the Orchestrator Input similarly to your JSON file, and with raw orch input of
JSON:
{
  "branch": "AGSP",
  "lotNumber": "2025",
  "GetInventoryDetail": "{ \"tableId\": \"V41021G\", \"rowset\": [ { \"branch\": \" AGSP\", \"lotNumber\": \"2025\", \"location\": \"13\", \"qtyOnHand\": 1821, \"qtyOnPO\": 0, \"qtyHardCommit\": 0, \"qtyHardCommitWO\": 0, \"itemNumber\": \"00080\" } ], \"records\": 1, \"moreRecords\": false }",
  "Total": "1821"
}
 
Try this:
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);
  jsonIn.GetInventoryDetail.rowset[0].put("Total",jsonIn.get("Total"));
  jsonIn.remove("Total");
  // modify jsonIn;
  def jsonOut = new JsonBuilder(jsonIn).toString();
  // orchAttr.writeWarn("custom log entry - warning");
  // orchAttr.writeDebug("custom log entry - debug");
  return jsonOut;
}

This works with me structuring the Orchestrator Input similarly to your JSON file, and with raw orch input of
JSON:
{
  "branch": "AGSP",
  "lotNumber": "2025",
  "GetInventoryDetail": "{ \"tableId\": \"V41021G\", \"rowset\": [ { \"branch\": \" AGSP\", \"lotNumber\": \"2025\", \"location\": \"13\", \"qtyOnHand\": 1821, \"qtyOnPO\": 0, \"qtyHardCommit\": 0, \"qtyHardCommitWO\": 0, \"itemNumber\": \"00080\" } ], \"records\": 1, \"moreRecords\": false }",
  "Total": "1821"
}
Thank you I will give it a try.
 
@DaveWagoner - thanks for the assistance it was a great help. I am now trying to figure out how to get 'itemNumber' to repeat in my scenario for 3 records. It only displays 'itemNumber' on the 1st iteration but the 2nd and 3rd iteration it does not display.

{
"branch": "QSP",
"lotNumber": "23032",
"location": "*",
"itemNumber": "46014",
"itemDescription": "Stouff,Spag&MeatSce,12p/12oz",
"UOM": "CS",
"XREF": "C:11005203 MB: SB: LP:11005203 UP:10013800120073",
"palletCount": 90,
"dateBestBefore": "2024-02-01",
"dateLotEffectivity": "2023-02-01",
"dateLotExpiration": "2024-02-01",
"dateOnHand": "2023-02-01",
"brand": "NES",
"allergens": "MSW",
"shelfLifeDays": 365,
"palletTrackingRequired": "Y",
"UOMDescription": "Case",
"GetInventoryDetail": {
"formId": "P5541202_W5541202A",
"gridId": "319",
"title": "Work With Item Availability",
"rowset": [
{
"qtyOnHand": 396,
"qtyHardCommit": 0,
"qtyAvailable": 396,
"lot": "23032",
"qtyHardCommitWO": 0,
"qtyOnPO": 0,
"branch": " QSP",
"location": "D1000",
"itemNumber": "46014"
},
{
"qtyOnHand": 327,
"qtyHardCommit": 0,
"qtyAvailable": 327,
"lot": "23032",
"qtyHardCommitWO": 0,
"qtyOnPO": 0,
"branch": " QSP",
"location": "STAGED"
},
{
"qtyOnHand": 792,
"qtyHardCommit": 396,
"qtyAvailable": 396,
"lot": "23032",
"qtyHardCommitWO": 0,
"qtyOnPO": 0,
"branch": " QSP",
"location": "TRUCK"
}
],
"records": 3,
"moreRecords": false
}
}



My code for output manipulation is below.


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);

jsonIn.GetInventoryDetail.rowset[0].put("itemNumber",jsonIn.get("itemNumber"));



// modify jsonIn;

def jsonOut = new JsonBuilder(jsonIn).toString();

// orchAttr.writeWarn("custom log entry - warning");

// orchAttr.writeDebug("custom log entry - debug");

return jsonOut;

}
 

Attachments

  • JsonOutput.jpg
    JsonOutput.jpg
    26.8 KB · Views: 14
Arrays are fun in their own right. Here's one I had to google. Give it a shot-- if it doesn't work right off the bat it must just be a bit of syntax I borked up. Just in case the element exists within the array I started with the .remove command.

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);
jsonIn.GetInventoryDetail.rowset.each {
   it.remove("itemNumber");
   it.put("itemNumber",jsonIn.get("itemNumber");
};

// modify jsonIn;
def jsonOut = new JsonBuilder(jsonIn).toString();
// orchAttr.writeWarn("custom log entry - warning");
// orchAttr.writeDebug("custom log entry - debug");

return jsonOut;

}
 
This is another way to do the task, i hope that will help.

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;
for(item in jsonIn.GetInventoryDetail.rowset)
{
   if(item.constainsKey("itemNumber"))
   {
      item.remove("itemNumber");
   }
   item.put("itemNumber",jsonIn.get("itemNumber");
}
def jsonOut = new JsonBuilder(jsonIn).toString();
// orchAttr.writeWarn("custom log entry - warning");
// orchAttr.writeDebug("custom log entry - debug");

return jsonOut;
}
 
I love it! Groovy is so fun. It's refreshing to be able to touch actual code instead of double clicking things in ER logic :D
 
Back
Top