有一个套件,我在其中创建了一个搜索按钮、过滤字段和一个子列表。 最初子列表是空的。当用户输入值来过滤字段并单击“搜索”按钮时,它会运行保存的搜索以获取过滤后的交易。由于在 Search btn click is on Client Script Netsuite 上运行的函数在尝试在子列表上添加行时返回此错误
TypeError: Cannot read properties of undefined (reading '0')
。
这是我的套房:
function onGetRequest(scriptContext) {
const form = serverWidget.createForm({
title: 'Suitelet',
});
form.clientScriptModulePath =
'../client/cl_script.js';
createFilterFields(form);
createTransactionsSublist(form);
createButtons(form);
scriptContext.response.writePage(form);
}
function createTransactionsSublist(form) {
const sublist = form.addSublist({
id: CUSTPAGE_TXNS_SUBLIST,
type: serverWidget.SublistType.LIST,
label: 'Transactions',
});
sublist.addField({
id: CUSTPAGE_TXNS_SUBLIST_TYPE,
label: 'Type',
type: serverWidget.FieldType.TEXT,
}).updateDisplayType({
displayType: serverWidget.FieldDisplayType.ENTRY,
});
}
function createButtons(form) {
form.addButton({
id: CUSTPAGE_SEARCH_BUTTON,
label: 'Search',
functionName: 'onSearchButtonClick',
});
}
这是客户端脚本的一部分:
function onSearchButtonClick() {
const currRec = currentRecord.get();
const filterValues = getTransactionSearchFilterValues(currRec);
const filteredTransactions = getFilteredTransactions(filterValues);
currRec.selectNewLine({
sublistId: CUSTPAGE_TXNS_SUBLIST,
});
currRec.setCurrentSublistValue({
sublistId: CUSTPAGE_TXNS_SUBLIST,
fieldId: CUSTPAGE_TXNS_SUBLIST_TYPE,
value: 'Test text',
});
currRec.commitLine({
sublistId: CUSTPAGE_TXNS_SUBLIST,
});
}
根据文档,我似乎做得正确,但仍然失败。 当我尝试将子列表类型更改为 INLINEEDITOR 时,这有效并且正在填充子列表。但是我需要用 LIST 类型来实现这一点。 可能有一种方法可以填充 suitelet 上的子列表,但我不知道如何将交易数据传递回 suitelet。
LIST
子列表有固定行数;您无法通过脚本或 UI 在 LIST
中添加或删除行。
正如您所见,
INLINEEDITOR
可以与您的技术方法正确配合。
如果您必须有
LIST
,则需要在服务器端而不是客户端填充结果。您可以使用 Search
而不是 addSubmitButton()
来创建 addButton()
按钮,从而将其变成“提交”按钮。单击后,将向 Suitelet 提交 POST
请求,并在传入请求中填充过滤器字段中指定的值。
虽然我根本不推荐这种编码风格(将所有逻辑放在一个入口点函数中),但您可以在 NetSuite 的示例中看到如何读取字段值的示例此处。