Skip to content

Commit 43093f3

Browse files
author
Matt Casters
committed
Fix for issue #4460
1 parent 1cbb1af commit 43093f3

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

plugins/transforms/javascript/src/main/java/org/apache/hop/pipeline/transforms/javascript/ScriptValuesAddedFunctions.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public class ScriptValuesAddedFunctions extends ScriptableObject {
142142
"trim",
143143
"substr",
144144
"getVariable",
145+
"resolveVariable",
145146
"setVariable",
146147
"LuhnCheck",
147148
"getDigitsOnly",
@@ -2000,6 +2001,35 @@ public static String getVariable(
20002001
return sRC;
20012002
}
20022003

2004+
public static String resolveVariable(
2005+
Context actualContext, Scriptable actualObject, Object[] argList, Function functionContext) {
2006+
String sRC = "";
2007+
String sArg1 = "";
2008+
if (argList.length == 1) {
2009+
try {
2010+
Object scmo = actualObject.get(CONST_TRANSFORM, actualObject);
2011+
Object scmO = Context.jsToJava(scmo, ITransform.class);
2012+
2013+
if (scmO instanceof ITransform) {
2014+
ITransform scm = (ITransform) Context.jsToJava(scmO, ITransform.class);
2015+
2016+
sArg1 = Context.toString(argList[0]);
2017+
return scm.resolve(sArg1);
2018+
} else {
2019+
// running via the Test button in a dialog
2020+
sArg1 = Context.toString(argList[0]);
2021+
return sArg1;
2022+
}
2023+
} catch (Exception e) {
2024+
sRC = "";
2025+
}
2026+
} else {
2027+
throw Context.reportRuntimeError(
2028+
"The function call resolveVariable accepts a single argument.");
2029+
}
2030+
return sRC;
2031+
}
2032+
20032033
// Return the output row metadata
20042034
public static IRowMeta getOutputRowMeta(
20052035
Context actualContext, Scriptable actualObject, Object[] argList, Function functionContext) {

plugins/transforms/javascript/src/main/resources/org/apache/hop/pipeline/transforms/javascript/jsFunctionHelp.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,25 @@
12481248
</Arguments>
12491249
</jsFunction>
12501250

1251+
<jsFunction name="resolveVariable">
1252+
<help>Resolves a variable expression.</help>
1253+
<sample>// Converts the given variable expression into its underlying value.
1254+
//
1255+
// Usage:
1256+
// resolveVariable(var);
1257+
// 1: String - The variable expression to resolve.
1258+
//
1259+
// 2025-01-27
1260+
//
1261+
var strVarName="${PROJECT_HOME}/output/";
1262+
Alert(resolveVariable(strVarName));
1263+
</sample>
1264+
<type>4</type>
1265+
<Arguments>
1266+
<argument id="1">var</argument>
1267+
</Arguments>
1268+
</jsFunction>
1269+
12511270
<jsFunction name="LuhnCheck">
12521271
<help>Check if the given Value is a valid Card Number using the Luhn algorithm.</help>
12531272
<sample>// Returns true, if the given value is a valid card number

0 commit comments

Comments
 (0)