我刚开始使用NetSuite和SuiteScript 2.0。这是我的需要:
我需要根据记录创建一个列表,然后我需要在列表中选择所需的行来仅为所选行调用一个函数。
目前,我创建了一个列表(使用N / ui / serverWidget.List对象),我能够使用N / search模块显示我的记录中的行来提供我的列表,我还在列表上创建了一个按钮,所以我可以调用一个函数。
我卡住的地方是选择列表中出现的行,以便仅为所选行触发一个函数。
使用API,我尝试为列表添加一个CHECKBOX类型的列,但它不起作用。
你知道实现这个目标的最佳方法吗?
谢谢。
以下是使用Suitelet将复选框添加到子列表的示例。您可以通过循环遍历行并检查字段是否为true来在客户端脚本中处理它们。
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();
}
}