E9.2 Orchestration Input - Arrays

Stank1964

Well Known Member
I have an Orchestration that targets Sales Entry, surprise... The issue is that the input includes a shipping charge which happens to be sent on the request outside of the line item(s) (which is an array).

So, since JDE charges shipping costs as order lines items, I want to add the shipping charge to the input line item(s) array. That sounds good, right?

Well, in order to do that I have to use groovy and unfortunately as of this date and time, I cannot get groovy to update an ORCH input or an ORCH variable. If anyone know how to do this, please share it, it would be incredibly useful to us.

Anyway, I created some groovy groovy that reads the input, loops thru the array and adds an element for the shipping. Unfortunately, when I try to use this new array as input to the forms request, I cannot map the individual columns of the newly created 2 dimensional line item array. I only see the groovy outputted array, not columns. Annoying.

Any ideas?

Thanks!
 
Here is the ORCH input..

{
"code": "6000006015",
"entries":
[
{
"entryNumber": 0,
"productCode": "E02852",
"qty": 1,
"discountedUnitTotalPrice": 35.01
},
{
"entryNumber": 1,
"productCode": "E00811",
"qty": 1,
"discountedUnitTotalPrice": 44.91
}
],
"deliveryMode":
{
"code": "Ground",
"deliveryCost": 9.95
},
"shippingAddress":
{
"jdeAddress": "331358",
"firstName": "Carmine",
"lastName": "Di Gruttola",
"line1": "701 E 36th Ave",
"phone": "+1 907-563-0658",
"postalCode": "36853",
"shortState": "AL",
"town": "Dadeville"
},
"billingAddress":
{
"jdeAddress": "331356"
},
"orderType": "SN"
}
 
And the groovy... The first step in the ORCH is to map the ORCH input into this groovy script which flattens it and adds the shipping line to the "entries" array.

import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
import groovy.json.*;

HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
HashMap<String, Object> returnMap = new HashMap<String, Object>();

//Input is the full output of the data request
String inDataSet = (String)inputMap.get("inDataSet");

//create an object out of it
def jsonSlurper = new JsonSlurper();
def jsonObject = jsonSlurper.parseText(inDataSet);

Integer inEntryNo;
String inProduct;
Integer inQty;
Number inPrice;

//get the record set
def dataset = jsonObject.entries;
//orchAttr.writeWarn("custom log entry - warning $dataset");

for(item in dataset){
inEntryNo = item.entryNumber + 1;
inProduct = item.productCode;
inQty = item.qty;
inPrice = item.discountedUnitTotalPrice;

item.remove("entryNumber");
item.remove("productCode");
item.remove("qty");
item.remove("discountedUnitTotalPrice");

item.put("entryNumber",inEntryNo);
item.put("productCode",inProduct);
item.put("qty",inQty);
item.put("discountedUnitTotalPrice",inPrice);
}

returnMap.put("out_DCTO", jsonObject.orderType);
returnMap.put("out_AN8", jsonObject.billingAddress.jdeAddress);
returnMap.put("out_SHAN", jsonObject.shippingAddress.jdeAddress);
returnMap.put("out_MLNM", jsonObject.shippingAddress.firstName + ' ' + jsonObject.shippingAddress.lastName);
returnMap.put("out_ADD1", jsonObject.shippingAddress.line1);
returnMap.put("out_ADD2", jsonObject.shippingAddress.line2);
returnMap.put("out_CTY1", jsonObject.shippingAddress.town);
returnMap.put("out_ADDS", jsonObject.shippingAddress.shortState);
returnMap.put("out_ADDZ", jsonObject.shippingAddress.postalCode);
returnMap.put("out_PH1", jsonObject.shippingAddress.phone);
returnMap.put("out_VR01", jsonObject.code);
returnMap.put("out_FRTH", jsonObject.deliveryMode.code);
returnMap.put("out_Shipping", jsonObject.deliveryMode.deliveryCost);

def newArray = [:];
newArray.entryNumber = inEntryNo + 1;
newArray.productCode = "SHIPPING";
newArray.qty = 1;
newArray.discountedUnitTotalPrice = jsonObject.deliveryMode.deliveryCost;
dataset.push(newArray);

def newEntries = new JsonBuilder(jsonObject.entries).toString()
returnMap.put("outEntries", newEntries);
return returnMap;
}
 
Back
Top