如何在 Suitelet 的列表 (serverWidget.List) 中添加复选框
How to add checkbox in a list (serverWidget.List) in Suitelet
我刚开始使用 NetSuite 和 SuiteScript 2.0。这是我的需求:
我需要创建一个基于记录的列表,然后我需要 select 列表中的所需行来仅调用 selected 行的函数。
目前,我创建了一个列表(使用 N/ui/serverWidget.List 对象),并且我能够使用 N/search 模块显示记录中的行来提供我的列表,我还创建了列表上的一个按钮,这样我就可以调用一个函数。
我遇到困难的地方是 select 出现在列表中的行,以便仅针对 selected 行触发函数。
对于 API,我尝试为列表添加一个 CHECKBOX 类型的列,但它不起作用。
您知道实现该目标的最佳方法吗?
谢谢。
下面是一个使用 Suitelet 将复选框添加到子列表的示例。您将在客户端脚本中处理它们,方法是遍历行并检查字段是否为真。
function onRequest(context) {
// Create the form
function createForm() {
try {
var form = serverWidget.createForm({
title: 'My Form',
hideNavBar: false
});
// In the client script, handle the checked lines by looping over the
// custpage_table sublist and looking to see if custpage_wo_process is true
form.clientScriptModulePath = 'SomeScript.js';
form.addButton({
id: 'custpage_myaction',
label: 'Process',
functionName: 'printRecords'
});
// Add a sublist to the form
var sublist = form.addSublist({
id: 'custpage_table',
type: serverWidget.SublistType.LIST,
label: 'Records to Process'
});
// Show a 'Mark All' button
sublist.addMarkAllButtons();
// Add an internalid to track the line item
var idField = sublist.addField({
id: 'custpage_rec_id',
label: 'Internal ID',
type: serverWidget.FieldType.TEXT
});
idField.updateDisplayType({
displayType: serverWidget.FieldDisplayType.HIDDEN
});
// Add a checkbox to mark which records should be processed
var printField = sublist.addField({
id: 'custpage_rec_process',
label: 'Process',
type: serverWidget.FieldType.CHECKBOX
});
// return the form and sublist
return {form: form, sublist: sublist};
} catch (e) {
log.error('Error creating form.', e);
}
}
function handleGet() {
var myForm = createForm();
if (myForm) {
// Get the form
var form = myForm.form;
// Get the sublist
var sublist = myForm.sublist;
// Do a search, etc to get the records to add to the sublist
var addResults = fetchSearchResult();
// Add the values to the sublist
for (var i = 0; i < addResults.length; i++) {
sublist.setSublistValue({
id: 'custpage_rec_id',
line: i,
value: addResults[i].id
});
}
context.response.writePage(form);
}
}
if (context.request.method === 'GET') {
handleGet();
}
}
我刚开始使用 NetSuite 和 SuiteScript 2.0。这是我的需求:
我需要创建一个基于记录的列表,然后我需要 select 列表中的所需行来仅调用 selected 行的函数。
目前,我创建了一个列表(使用 N/ui/serverWidget.List 对象),并且我能够使用 N/search 模块显示记录中的行来提供我的列表,我还创建了列表上的一个按钮,这样我就可以调用一个函数。
我遇到困难的地方是 select 出现在列表中的行,以便仅针对 selected 行触发函数。
对于 API,我尝试为列表添加一个 CHECKBOX 类型的列,但它不起作用。
您知道实现该目标的最佳方法吗?
谢谢。
下面是一个使用 Suitelet 将复选框添加到子列表的示例。您将在客户端脚本中处理它们,方法是遍历行并检查字段是否为真。
function onRequest(context) {
// Create the form
function createForm() {
try {
var form = serverWidget.createForm({
title: 'My Form',
hideNavBar: false
});
// In the client script, handle the checked lines by looping over the
// custpage_table sublist and looking to see if custpage_wo_process is true
form.clientScriptModulePath = 'SomeScript.js';
form.addButton({
id: 'custpage_myaction',
label: 'Process',
functionName: 'printRecords'
});
// Add a sublist to the form
var sublist = form.addSublist({
id: 'custpage_table',
type: serverWidget.SublistType.LIST,
label: 'Records to Process'
});
// Show a 'Mark All' button
sublist.addMarkAllButtons();
// Add an internalid to track the line item
var idField = sublist.addField({
id: 'custpage_rec_id',
label: 'Internal ID',
type: serverWidget.FieldType.TEXT
});
idField.updateDisplayType({
displayType: serverWidget.FieldDisplayType.HIDDEN
});
// Add a checkbox to mark which records should be processed
var printField = sublist.addField({
id: 'custpage_rec_process',
label: 'Process',
type: serverWidget.FieldType.CHECKBOX
});
// return the form and sublist
return {form: form, sublist: sublist};
} catch (e) {
log.error('Error creating form.', e);
}
}
function handleGet() {
var myForm = createForm();
if (myForm) {
// Get the form
var form = myForm.form;
// Get the sublist
var sublist = myForm.sublist;
// Do a search, etc to get the records to add to the sublist
var addResults = fetchSearchResult();
// Add the values to the sublist
for (var i = 0; i < addResults.length; i++) {
sublist.setSublistValue({
id: 'custpage_rec_id',
line: i,
value: addResults[i].id
});
}
context.response.writePage(form);
}
}
if (context.request.method === 'GET') {
handleGet();
}
}