Flow math "invalid return type: java.math.BigDecimal"

Kelly Logan
Kilo Sage

I want to take the value of two fields, both declared as Decimal, add them and put the total into a third field, also Decimal. 

I used a script to do so (open to other options):

 

var tot = fd_data.flow_var.total + fd_data._7__for_each.item.u_actual_quantity;
return tot;

 

But this step errors out mid-run (logs are on previous step) with the detail "invalid return type: java.math.BigDecimal". Any ideas? Again, happy to use another method to add two decimal values.

 

Here's a couple of the log entries that seem pertinent:
Flow Designer: Operation(u_Contract Billing Processor.ForEach$1.item$8) failed with error: com.snc.process_flow.exception.OpException: Call block 'u_Contract Billing Processor.ForEach$1.item$8' failed. Detail: Call block '411312c683818250c43ac0e0deaad316.ForEach$1.item$1' failed. Detail: invalid return type: java.math.BigDecimal at com.snc.process_flow.engine.CallBlockOperation.run(CallBlockOpera...

...

Flow Designer: Operation(c11312c683818250c43ac0e0deaad320.quantity_plus_total.InlineScript_quantity_plus_total061352c6d98182506c29891bb08b4a8a) failed with error: java.lang.RuntimeException: invalid return type: java.math.BigDecimal at com.glide.script.fencing.ScopedFunctionObjectTypeHandler.coerceReturnValue(ScopedFunctionObjectTypeHandler.java:332) at com.glide.script.fencing.ScopedFunctionObj...

 

4 REPLIES 4

Kelly Logan
Kilo Sage

Okay, I think I found the issue. I created a test action to add two decimals with this script:

(function execute(inputs, outputs) {
outputs.result = inputs.d1 + inputs.d2;
})(inputs, outputs);

See if you can spot the problem. . .

KellyLogan_0-1711031635966.png

 

Kelly Logan
Kilo Sage

Okay, looks like this is the old decimal issue, but ServiceNow is getting caught partway through conversion and doing string concatenation instead. It doesn't look like I have the .toFixed() method available, but I skipped it and used an old solution that works internally in the action:

(function execute(inputs, outputs) {
    var d1 = inputs.d1;
    var d2 = inputs.d2;
    outputs.result = (d1 * 1000 + d2 * 1000) / 1000;
})(inputs, outputs);

KellyLogan_0-1711034776570.png

But when I try to use the action, feeding it two decimal data pills, I get an internal server error. 

 

Can someone please help me teach ServiceNow how to add two numbers?

 

 

Kelly Logan
Kilo Sage

The critical factor, which perhaps I should have mentioned earlier, appears to be that the above mentioned subflow is scoped in our custom app: "com.snc.process_flow.engine.restricted_caller_access.ExecuteWithCallerAccessTracking.executeWithMetaStack(ExecuteWithCallerAccessTracking.java:31)"

So if it is a cross-scope issue, what would I grant permissions to? I added the full log below in case anyone can parse out the routine before I do. In the meantime, I can workaround by doing math in global actions. 

 

Here is the complete log entry:
Flow Designer: Operation(Test decimal math.result.InlineScript_result4027f1eaadc9ca50dc3c4d3c31a02dd9) failed with error: java.lang.RuntimeException: invalid return type: java.math.BigDecimal
at com.glide.script.fencing.ScopedFunctionObjectTypeHandler.coerceReturnValue(ScopedFunctionObjectTypeHandler.java:332)
at com.glide.script.fencing.ScopedFunctionObjectTypeHandler.mapToObject(ScopedFunctionObjectTypeHandler.java:262)
at com.glide.script.fencing.ScopedFunctionObjectTypeHandler.coerceReturnValue(ScopedFunctionObjectTypeHandler.java:302)
at com.glide.script.fencing.ScopedFunctionObjectTypeHandler.coerceFunctionReturnValue(ScopedFunctionObjectTypeHandler.java:339)
at com.snc.process_flow.operation.GlidePFScriptEvaluator.convertToJsMap(GlidePFScriptEvaluator.java:70)
at com.snc.process_flow.operation.GlidePFScriptEvaluator.runScript(GlidePFScriptEvaluator.java:40)
at com.snc.process_flow.operation.script.ScriptOperationBase.runScript(ScriptOperationBase.java:50)
at com.snc.process_flow.operation.script.ScriptOperation.run(ScriptOperation.java:75)
at com.snc.process_flow.engine.Operation.execute(Operation.java:207)
at com.snc.process_flow.engine.restricted_caller_access.ExecuteWithCallerAccessTracking.executeWithMetaStack(ExecuteWithCallerAccessTracking.java:31)
at com.snc.process_flow.engine.ProcessEngine.executeOps(ProcessEngine.java:618)
at com.snc.process_flow.engine.ProcessEngine.runInternal(ProcessEngine.java:515)
at com.snc.process_flow.engine.ProcessEngine.run(ProcessEngine.java:502)
at com.snc.process_flow.engine.ProcessAutomation.run(ProcessAutomation.java:101)
at com.snc.process_flow.engine.GlideProcessAutomation.runSync(GlideProcessAutomation.java:184)
at com.snc.process_flow.engine.GlideProcessAutomation.runWithDomain(GlideProcessAutomation.java:343)
at com.snc.process_flow.engine.GlideProcessAutomation.lambda$runAsUserSync$1(GlideProcessAutomation.java:310)
at com.snc.process_flow.engine.PFSessionClone.run(PFSessionClone.java:71)
at com.snc.process_flow.engine.GlidePFSession.runPlanAsUserSession(GlidePFSession.java:42)
at com.snc.process_flow.engine.GlideProcessAutomation.runAsUserSync(GlideProcessAutomation.java:308)
at com.snc.process_flow.engine.GlideProcessAutomation.messageFlow(GlideProcessAutomation.java:394)
at com.snc.process_flow.engine.GlideProcessAutomation._start(GlideProcessAutomation.java:606)
at com.snc.process_flow.engine.GlideProcessAutomation$StartBuilder.start(GlideProcessAutomation.java:1526)
at com.glide.flow.providers.FlowGlideProvider.testSubFlow(FlowGlideProvider.java:1815)
at com.glide.flow.providers.FlowGlideProvider.testFlow(FlowGlideProvider.java:1783)
at com.glide.flow_design.rest.FlowService.testRunFlow(FlowService.java:815)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.glide.rest.handler.impl.ServiceHandlerImpl.invokeService(ServiceHandlerImpl.java:44)
at com.glide.rest.processors.RESTAPIProcessor.process(RESTAPIProcessor.java:346)
at com.glide.processors.AProcessor.runProcessor(AProcessor.java:733)
at com.glide.processors.AProcessor.processTransaction(AProcessor.java:291)
at com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:187)
at com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:175)
at com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:58)
at com.glide.sys.Transaction.run(Transaction.java:2645)
at com.glide.ui.HTTPTransaction.run(HTTPTransaction.java:30)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)

Kelly Logan
Kilo Sage

So far, the only solution found is to move decimal math into global Actions called from the scoped flows. Not ideal, but workable for now.