ServerRequest.getLineCount(options)

Method Description

Returns the number of lines in a sublist.

Returns

number

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

Errors

Error Code

Message

Thrown If

SSS_MISSING_REQD_ARGUMENT

Missing a required argument: {param name}

The options.group 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.getLineCount({
    group: 'sublistId'
});
...
// 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 getLineCount() returns the number of items in the 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"
            });
            sublist.setSublistValue({
                id : 'field1',
                line : 1,
                value : 'T'
            });
            sublist.setSublistValue({
                id : 'field2',
                line : 1,
                value : "value 2"
            });
             
            form.addSubmitButton({
                id: 'submitBtn',
                label: 'Submit'
            });
         
            response.writePage(form);
        }
        else if (request.method === 'POST')
        {
            var lineCount = request.getLineCount('custpage_sample_list'); // 2
             
            for (var i = 0; i < lineCount; i++)
            {
            ...
            // Add additional code
            ...
            }
        }   
    }
 
    return {
        onRequest: onRequest
    };
}); 

          

Related Topics

General Notices