ServerRequest.getSublistValue(options)

Method Description

Returns the value of a sublist line item.

Returns

string

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/https Module

Since

2015.2

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.group

string

required

The sublist internal ID.

2015.2

options.line

string

required

The sublist line number. Sublist index starts at 0.

2015.2

options.name

string

required

The name of the field.

2015.2

Errors

Error Code

Message

Thrown If

SSS_MISSING_REQD_ARGUMENT

Missing a required argument: {param name}

The options.group, options.line, or the options.name parameter is not specified.

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/https Module Script Samples.

          // Add additional code 
...
serverRequest.getSublistValue({
    group: 'item',
    name: 'amount',
    line: '2'
});
...
// Add additional code 

        

Code Samples

Note:

This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects.

Defines a Suitelet which generates a form. When the user fills in and sends the form, the getSublistValue({ returns the specific field's value on the given line in the given sublist.

          /**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 */
define(['N/ui/serverWidget'], function(serverWidget) {
    function onRequest(context) {
        var request = context.request;
        var response = context.response;
 
        if (request.method === 'GET')
        {
            var form = serverWidget.createForm({
                title : 'Sample Form'
            });
 
            var sublist = form.addSublist({
                id : 'custpage_sample_list',
                label : 'Sample List',
                type : serverWidget.SublistType.LIST
            });
            sublist.addField({
                id : 'field1',
                label : 'Field Name 1',
                type : serverWidget.FieldType.CHECKBOX
            });
            sublist.addField({
                id : 'field2',
                label : 'Field Name 2',
                type : serverWidget.FieldType.TEXT
            })
            sublist.setSublistValue({
                id : 'field1',
                line : 0,
                value : 'F'
            });
            sublist.setSublistValue({
                id : 'field2',
                line : 0,
                value : "value 1"
            });
             
            form.addSubmitButton({
                id: 'submitBtn',
                label: 'Submit'
            });
         
            response.writePage(form);
        }
        else if (request.method === 'POST')
        {
            var lineCount = request.getLineCount('custpage_sample_list');
             
            for (var i = 0; i < lineCount; i++)
            {
                var field1 = request.getSublistValue({
                    group : 'custpage_sample_list',
                    name : 'field1',
                    line : i
                }); // "F"
                var field2 = request.getSublistValue({
                    group : 'custpage_sample_list',
                    name : 'field2',
                    line : i
                }); // "value 1"
                ...
                // Add additional code
            }
        }   
    }
 
    return {
        onRequest: onRequest
    };
}); 

        

Related Topics

General Notices