我有一个下拉列表,当选择一个特定选项时,将显示一个隐藏字段,并且该字段具有新值。我能够显示该字段,但无法用该值填充该字段。下面的脚本:
function fieldChanged(context) {
var records = context.currentRecord;
if (context.fieldId == 'custbody_data') {
var note = context.currentRecord.getField({ fieldId: 'custbody_note' });
var type = records.getValue({
fieldId: 'custbody_data'
});
if (type == "2") {
note.isDisplay = true;
note.setValue = "test";
} else if (type == "1") {
note.isDisplay = false;
note.setValue = "";
}
}
}
return {
fieldChanged: fieldChanged
}
note.setValue = "";
您尝试做的事情有两个问题:
使用NetSuite API,要操作记录中的字段值,您需要使用N/currentRecord#Record
对象,而不是N/currentRecord#Field
。换句话说,您需要呼叫context.currentRecord.setValue()
。
setValue
是method, not a property。即您需要使用新值调用函数setValue()
,而不要像尝试那样为它分配一个值(note.setValue = "new value"
)。
将它们放在一起,更新字段值的正确语法是:
context.currentRecord.setValue({
fieldId: 'custbody_note',
value: "test",
});