如何向表单子列表添加新行?我正在使用SuiteScript 2.0 Suitelet。任何建议都会非常有帮助。
function initForm(context) {
var form = ui.createForm({
title: 'Generate Lab Request File'
});
var sublist = form.addSublist({
id: 'sublist',
type: ui.SublistType.LIST, //.INLINEEDITOR,
label: 'Panels'
});
sublist.addField({
id: 'export_version',
type: ui.FieldType.FLOAT,
label: 'Export Version'});
// Fails because row 1 doesn't exist. How can I add a new row?
sublist.setSublistValue({
id : 'export_version',
line : 1, // I'm trying to add a new row. I already have row 0
value : "6.0"
});
// Error function doesn't exist
sublist.addRows({
rows: [{export_version : '6.0'},
{export_version : '6.0'}]
});
context.response.writePage(form);
}
答案 0 :(得分:1)
SuiteScript 2.0 API文档中有一个很好的示例。您只需选择一个新行。我在下面的示例脚本中注意到了它。希望有所帮助。
**
*@NApiVersion 2.x
*/
require(['N/record'], function(record) {
function createPurchaseOrder() {
var rec = record.create({
type: 'purchaseorder',
isDynamic: true
});
rec.setValue({
fieldId: 'entity',
value: 52
});
rec.setValue({
fieldId: 'location',
value: 2
});
/******/
//Here is where you are adding a new line.
/******/
rec.selectNewLine({
sublistId: 'item'
});
rec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 190
});
rec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: 2
});
subrecordInvDetail = rec.getCurrentSublistSubrecord({
sublistId: 'item',
fieldId: 'inventorydetail'
});
subrecordInvDetail.selectNewLine({
sublistId: 'inventoryassignment'
});
subrecordInvDetail.setCurrentSublistValue({
sublistId: 'inventoryassignment',
fieldId: 'receiptinventorynumber',
value: 'myinventoryNumber'
});
subrecordInvDetail.commitLine({
sublistId: 'inventoryassignment'
});
subrecordInvDetail.selectLine({
sublistId: 'inventoryassignment',
line: 0
});
var myInventoryNumber = subrecordInvDetail.getCurrentSublistValue({
sublistId: 'inventoryassignment',
fieldId: 'receiptinventorynumber'
});
}
createPurchaseOrder();
});