NetSuiteのSuiteletを使用すると、カスタムページを作成できます。Suiteletの一般的な実装の一つは、ユーザーデータを取得して表示用に処理することです。Suiteletで作成されたフィールドにアクセスするには、ServerRequest.parametersを使用します。Suitelet内のサブリストデータにアクセスするために、SuiteScript 2.x APIは次の2つのメソッドを提供します:ServerRequest.getLineCount(options)とServerRequest.getSublistValue(options)。
- ServerRequest.getLineCount(options)は、サブリストの合計行数を返します。
- ServerRequest.getSublistValue(options)は、特定のサブリスト行項目の値を返します。
以下に、これらのメソッドの使用例を示します:
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/ui/serverWidget', 'N/log'], function(serverWidget, log) {
function onRequest(context) {
if (context.request.method === 'GET') {
var form = serverWidget.createForm({
title: 'サンプルSuiteletフォーム'
});
// フォームにフィールドを追加
form.addField({
id: 'custpage_field',
type: serverWidget.FieldType.TEXT,
label: 'サンプルフィールド'
});
// フォームにサブリストを追加
var sublist = form.addSublist({
id: 'custpage_sublist',
type: serverWidget.SublistType.INLINEEDITOR,
label: 'サンプルサブリスト'
});
// サブリストにフィールドを追加
sublist.addField({
id: 'custpage_sublist_field1',
type: serverWidget.FieldType.TEXT,
label: 'サブリストフィールド1'
});
context.response.writePage(form);
} else {
var request = context.request;
var lineCount = request.getLineCount({ sublistId: 'custpage_sublist' });
for (var i = 0; i < lineCount; i++) {
var sublistValue = request.getSublistValue({
sublistId: 'custpage_sublist',
fieldId: 'custpage_sublist_field1',
line: i
});
log.debug('Sublist Value', sublistValue);
}
}
}
return