Suitescript2.0-如何显示字段并根据下拉列表更新值



我有一个下拉菜单,当选择特定选项时,将显示一个隐藏字段,该字段具有新值。我可以显示字段,但无法用值填充字段。下面的脚本:

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 = "";

您尝试做的事情有两个问题:

  1. 使用NetSuite API,要操作记录中字段的值,需要使用N/currentRecord#Record对象,而不是N/currentRecord#Field。换句话说,您需要呼叫context.currentRecord.setValue()

  2. setValue是一种方法,而不是属性。也就是说,您需要用新值调用函数setValue(),而不是像您尝试的那样为其赋值(note.setValue = "new value"(。

将这些放在一起,更新字段值的正确语法是:

context.currentRecord.setValue({
fieldId: 'custbody_note',
value: "test",
});

最新更新