Suitescript 2.0 - 如何显示字段并根据下拉列表更新值?
Suitescript 2.0 - How to show a field and update value based on dropdown?
I have a drop down that, when a particular option is selected a hidden field will be displayed and that field which have a new value.我能够显示该字段,但无法用该值填充该字段。脚本如下:
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。 IE。您需要使用新值调用函数 setValue()
,而不是像您尝试的那样为其分配一个值 (note.setValue = "new value"
)。
将它们放在一起,更新字段值的正确语法是:
context.currentRecord.setValue({
fieldId: 'custbody_note',
value: "test",
});
I have a drop down that, when a particular option is selected a hidden field will be displayed and that field which have a new value.我能够显示该字段,但无法用该值填充该字段。脚本如下:
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。 IE。您需要使用新值调用函数setValue()
,而不是像您尝试的那样为其分配一个值 (note.setValue = "new value"
)。
将它们放在一起,更新字段值的正确语法是:
context.currentRecord.setValue({
fieldId: 'custbody_note',
value: "test",
});