01-11-2022 03:57 AM
Hello,
i’m trying to nest a function in a map within an expression library, however what i get returned just the ‘callstack’ of the function.
Here’s the outcome:
[
{
"test":
"/* ArrowFunction @ line 5:10 */ () => __parent__.salesRegionMapper('accountableUnit', 8)"
}
]
The expression library is called like this:
lib.map.responsibleUnit['8']
Here is the expression library:
{
"responsibleUnit": {
"10": "Delivery",
"9": "Operation",
"8" : () => __parent__.salesRegionMapper('accountableUnit', 8),
"16": "Tolling Services"
},
"accountableUnit": [
[5, "Sales APAC"],
[7, "Sales EMENA"],
[8, "Sales EMENA"],
[19, "Sales LAM"],
[20, "Sales NAM"],
[21, "Sales Africa"],
[22, "Sales EMENA"],
[23, "Other"],
[24, "Sales EMENA"],
[37, "Tolling Services"],
[39, "Other"]
],
salesRegionMapper: (mappingTable, value) => this[mappingTable].find(x => x[0] == value)[1],
}
How can i get the function to actually execute and not just be ‘listed’?
Best regards
Thomas
Solved! Go to Solution.
01-11-2022 06:42 AM
Change your responsibleUnit to a function:
"responsibleUnit": (opt) => match opt {
"10" => "Delivery",
"9" => "Operation",
"8" => this.salesRegionMapper('accountableUnit', 8),
"16" => "Tolling Services",
_ => "unknown"
},
Then you can call as a function and it will drilldown to the salesRegionMapper function:
lib.testcall.responsibleUnit('8')
01-11-2022 04:22 AM
Hey @Henchway,
You just need to add parentheses at the end, that way “the function” can be treated as a proper function:
lib.map.responsibleUnit.8()
Hope this helps,
Bojan
01-11-2022 06:25 AM
I’m afraid that also doesn’t work.
Also this wouldn’t work generally in this case, as only in case of ‘8’, the result would be a function, in any other case it would be a value.
"error":
"Map type does not have a method named: eval, found in: ...] == value)[1]). Perhaps you meant: entries, extend, filter, get, getFirst, hasOwnProperty, hasPath, isEmpty, keys, mapKeys, mapValues, merge, salesRegionMapper, toString, values"
"stacktrace":
"com.snaplogic.snap.api.ExpressionException: Map type does not have a method named: eval, found in: ...] == value)[1]). Perhaps you meant: entries, extend, filter, get, getFirst, hasOwnProperty, hasPath, isEmpty, keys, mapKeys, mapValues, merge, salesRegionMapper, toString, values\r\n\tat sl.EvaluatorUtils.undefinedMethod(EvaluatorUtils.java:1775)\r\n\tat sl.EvaluatorUtils.method(EvaluatorUtils.java:783)\r\n\tat SC$2.eval(Unknown Source)\r\n\tat sl.EvaluatorUtils.methodInternal(EvaluatorUtils.java:860)\r\n\tat sl.EvaluatorUtils.method(EvaluatorUtils.java:780)\r\n\tat SC$1.eval(Unknown Source)\r\n\tat sl.EvaluatorUtils.methodInternal(EvaluatorUtils.java:860)\r\n\tat sl.EvaluatorUtils.method(EvaluatorUtils.java:780)\r\n\tat sl.EvaluatorUtils.method(EvaluatorUtils.java:772)\r\n\tat SC.evaluate(Unknown Source)\r\n\tat com.snaplogic.util.ExpressionUtils$MyExpressionProperty.eval(ExpressionUtils.java:281)\r\n\tat com.snaplogic.snap.api.impl.PropertyValuesImpl$ValidatingExpressionProperty.eval(PropertyValuesImpl.java:1005)\r\n\tat com.snaplogic.snaps.transform.DataTransform.processBinary(DataTransform.java:263)\r\n\tat com.snaplogic.snaps.transform.DataTransform.process(DataTransform.java:216)\r\n\tat com.snaplogic.snap.api.ExecutionUtil.process(ExecutionUtil.java:106)\r\n\tat com.snaplogic.snap.api.ExecutionUtil.execute(ExecutionUtil.java:70)\r\n\tat com.snaplogic.snap.api.SimpleSnap.execute(SimpleSnap.java:70)\r\n\tat com.snaplogic.cc.snap.common.SnapRunnableImpl.executeSnap(SnapRunnableImpl.java:800)\r\n\tat com.snaplogic.cc.snap.common.SnapRunnableImpl.executeForSuggest(SnapRunnableImpl.java:647)\r\n\tat com.snaplogic.cc.snap.common.SnapRunnableImpl.doRun(SnapRunnableImpl.java:856)\r\n\tat com.snaplogic.cc.snap.common.SnapRunnableImpl.call(SnapRunnableImpl.java:435)\r\n\tat com.snaplogic.cc.snap.common.SnapRunnableImpl.call(SnapRunnableImpl.java:117)\r\n\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\r\n\tat java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)\r\n\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\r\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\r\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\r\n\tat java.base/java.lang.Thread.run(Thread.java:834)\r\n"
01-11-2022 06:40 AM
Hi @Henchway,
Can you share your expression for this error ?
01-11-2022 06:42 AM
Change your responsibleUnit to a function:
"responsibleUnit": (opt) => match opt {
"10" => "Delivery",
"9" => "Operation",
"8" => this.salesRegionMapper('accountableUnit', 8),
"16" => "Tolling Services",
_ => "unknown"
},
Then you can call as a function and it will drilldown to the salesRegionMapper function:
lib.testcall.responsibleUnit('8')