Pentaho Javascript-行操作

Pentaho Javascript-行操作,javascript,pentaho,pentaho-data-integration,Javascript,Pentaho,Pentaho Data Integration,我试图在pentaho的旧版本(4.4)中使用javascript操纵一行,得到一些奇怪的结果,我无法解释/不理解pentaho在做什么 var test = 'field'; Alert (this[test]); //--> Undefined Alert (this['field']); // --> Expected result Alert (this[test]); //--> Expected Result 出于某种原因,在我使用文字字符串引用之前,此[test

我试图在pentaho的旧版本(4.4)中使用javascript操纵一行,得到一些奇怪的结果,我无法解释/不理解pentaho在做什么

var test = 'field';
Alert (this[test]); //--> Undefined
Alert (this['field']); // --> Expected result
Alert (this[test]); //--> Expected Result
出于某种原因,在我使用文字字符串引用之前,
此[test]
的初始请求是未定义的,这使得无法动态驱动进程(即,我无法通过引用访问行信息)

你知道为什么吗?这仅仅是Pentaho处理变量的方式吗?实际上,我希望最终结果允许我在任何给定位置更改行值。要么:

row[test] = 'New value


但是,如果不替换这些值,上述任何一项都不起作用,使其成为一个非常静态的过程。

据我所知,Kettle不会将字段添加到脚本的作用域中,除非该字段作为子字符串包含在脚本源代码中(即使注释中提到了字段,也应该添加)。请参阅
确定字段()
添加值()
方法()

因此,您提供的确切脚本实际上会生成三个已定义值或三个未定义值,具体取决于字段是否存在。只有在我从代码中完全删除了带有字段名的字符串,并在另一个字段中传递了字段名之后,我才能重现您的问题

因此,操纵行值的一种方法可以是提及脚本中的所有字段名(例如,在注释中),然后尝试使用setValue,就像您尝试过的那样(似乎仅在兼容模式下工作)

另一种可能的方法是使用
数组变量获取值,并使用
getInputRowMeta().indexOfValue(fieldName)
获取字段索引,例如:

var idx = getInputRowMeta().indexOfValue(fieldName)
// WARNING: you may assign value of any type this way
// and the value will not be converted to a type defined
// in the field's ValueMeta:
row[idx] = 'New value'
但是,这种方法绕过了类型转换,类型转换通常是在
getValueFromJScript()方法的JS步骤之外传递JavaScript值时执行的

例如,以下代码将在输出中放入无效值,您甚至可能不会注意到它,直到后续步骤以某种不正确的方式处理该值:

// Let's assume that fieldName is name of the 0th input field.
// I'd expect, that the value would remain the same
// but in fact the `fieldName` references some wrapper oject
// which looks similar to its value
// but has a different type
row[0] = fieldName;
在后续步骤中:

for(var i = 0; i < row.length; i++) {
    Alert(row[i]) // alerts same value as the input, e.g. 'test'
    Alert(row[i].class) // alerts undefined. While expected is 'java.lang.String'
    // Some other subsequent steps may crash once this value encountered
}
for(变量i=0;i
// Let's assume that fieldName is name of the 0th input field.
// I'd expect, that the value would remain the same
// but in fact the `fieldName` references some wrapper oject
// which looks similar to its value
// but has a different type
row[0] = fieldName;
for(var i = 0; i < row.length; i++) {
    Alert(row[i]) // alerts same value as the input, e.g. 'test'
    Alert(row[i].class) // alerts undefined. While expected is 'java.lang.String'
    // Some other subsequent steps may crash once this value encountered
}