E9.2 JDE Orchestrator: Custom request Groovy is not working for Array value

M.Nadeem Sabir

Member
I am facing problems while enabling the Groovy custom request for multiple lines, like an array input from Orchestrator.
I am getting the following error.


"message": {
"CREQ_TotalCostCHSARTOUSD": {
"Exception": "Exception",
"Message": "java.lang.NullPointerException"
}

I have created a custom function that takes the input value from the orchestrator Input array, does some calculations, and returns the value in multiple lines.
 
Can you post a screenshot of the groovy component (including inputs and outputs) and the text of the script?
 
Last edited:
import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.LinkedHashMap;
import groovy.json.JsonSlurper;
import java.util.HashMap;
import java.lang.Math;
import java.lang.String;
import java.lang.Object;
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
HashMap<String, Object> returnMap = new HashMap<String, Object>();
// Add logic here
//String totalcost = (String)inputMap.get("Extended_Cost");


// BigDecimal totalcost = new BigDecimal((String)inputMap.get("Unit_Cost"));
BigDecimal totalcost = new BigDecimal((String)inputMap.get("Extended_Cost"));
// BigDecimal usdcost = new BigDecimal((String)inputMap.get("Extended_Cost"));

// String totalcost = (String)inputMap.get("Extended_Cost");

def RoundingAmount = new java.util.LinkedHashMap();





//Change in USD
// PriceAmount.put("value", new DecimalFormat("0.00").format(jsonData.F4211_UPRC));
//Price.put("PriceAmount",PriceAmount)


returnMap.put("UnitCost", " ");
totalcost= totalcost/(3.76) ;
String bob = ""
bob = new DecimalFormat("0.00").format(Math.abs(totalcost));
//totalcost.put("value",new DecimalFormat("0.00").format(Math.abs(totalcost)));
// RoundingAmount.put("totalcost",new DecimalFormat("0.00").format(Math.abs(totalcost)));

//totalcostt.put("bob",bob);

returnMap.put("UnitCost", bob);


// returnMap.put("totalcost",totalcost);
//returnMap.put("totalcostt",bob);


// returnMap.put("UnitCost", bob)

return returnMap;
}
 

Attachments

  • Screenshot.PNG
    Screenshot.PNG
    64.3 KB · Views: 43
  • Screenshot-With Iterate option.PNG
    Screenshot-With Iterate option.PNG
    86 KB · Views: 43
  • payload.txt
    348 bytes · Views: 22
Hello,

I am using the a custom function request to convert in cost. The input cost in a different currency and output value in a different currency. The custom function only using from some calculation. It is working fine for a single line input. There is some issue with array input.(Multi lines)
 
import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.LinkedHashMap;
import groovy.json.JsonSlurper;
import java.util.HashMap;
import java.lang.Math;
import java.lang.String;
import java.lang.Object;
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
HashMap<String, Object> returnMap = new HashMap<String, Object>();
// Add logic here
//String totalcost = (String)inputMap.get("Extended_Cost");


// BigDecimal totalcost = new BigDecimal((String)inputMap.get("Unit_Cost"));
BigDecimal totalcost = new BigDecimal((String)inputMap.get("Extended_Cost"));
// BigDecimal usdcost = new BigDecimal((String)inputMap.get("Extended_Cost"));

// String totalcost = (String)inputMap.get("Extended_Cost");

def RoundingAmount = new java.util.LinkedHashMap();





//Change in USD
// PriceAmount.put("value", new DecimalFormat("0.00").format(jsonData.F4211_UPRC));
//Price.put("PriceAmount",PriceAmount)


returnMap.put("UnitCost", " ");
totalcost= totalcost/(3.76) ;
String bob = ""
bob = new DecimalFormat("0.00").format(Math.abs(totalcost));
//totalcost.put("value",new DecimalFormat("0.00").format(Math.abs(totalcost)));
// RoundingAmount.put("totalcost",new DecimalFormat("0.00").format(Math.abs(totalcost)));

//totalcostt.put("bob",bob);

returnMap.put("UnitCost", bob);


// returnMap.put("totalcost",totalcost);
//returnMap.put("totalcostt",bob);


// returnMap.put("UnitCost", bob)


return returnMap;
}


I am using a custom function request to convert the cost. The input cost is in a different currency, and the output value is in a different currency. The custom function only uses some calculations. It is working fine for a single line input. There is some issue with array input.(Multi lines)
 
Thank you for all of the excellent information!

Arrays can and do become a bit weird when used with iterate. And I think that if you could introspect into what your data looks like AFTER the scripting step (even if it didnt error out), you might find just a single variable with the most recent iteration of the data populated.

Also I have never seen orch inputs with manually-mapped array locations (GridData[1])! Is that actually working? What if instead of the manual map, you click the "raw" button and paste the payload json, then test your orch? I'm guessing you'll stop seeing the error at least.

I suspect that even if the scripting step wasn't erroring out (such as if you paste raw json payload to the input), you'd get wacky results when you try to add grid data in your form request and would only see 1 row of data go in.

I suggest the following pattern based on my own experience:
  1. For each form request that contains populate multiple grid rows, create a sub-orch by going to the Form Request, then the menu, then "create orchestration". Rename it appropriatetly, save that, and leave it alone. It is a delicate flower :)
  2. Add the new orchestration into your current orch where the form request is. Open the transformations box and click the "view example input" button, then save that input. It may very well match your payload.txt but might be a bit different.
  3. Prior to the sub-orchestration call, make a new script. This script will take the "parent" orch input including the array, process the data however you want (loop through the array, math the numbers, and come out of the other side with the array intact), and then build a json file that matches the format of the input you generated in #2. This is a very difficult step if you've never done it before, but I think it will be valuable for you to do considering that you're already pretty advanced with this stuff.
You are not involving iterate anymore-- in my opinion iterate is nice, but in very few cases, until Oracle allows things like iterations-inside-formrequests. It is good for single record by single record processing, not for preserving structured data like you need.

Step #3 is difficult and you might want to spend a little on consulting to get that going for you the first time, if you don't have the convenience of learning time.

I hope this is helpful-- and it's based on my own experience. Someone better than me at this stuff might have completely different advice!
 
Back
Top