Netsuite Tutorials: How to Create Sublist on Netsuite Form using 2.0 and Set values in sublist ?


How to create and set value in LIST sublist 2.0



 Hi All,

Today we are going to learn how to create LIST Sublist and how to set values in that sublist.
List Sublist is used to show lines on form , user can edit/view line items but is not allowed to any new line.

/**
 *@NApiVersion 2.x
 *@NScriptTyoe Suitelet
*/
define(['N/ui/serverWidget'],
function (serverWidget)
{
  function onRequest(context)
  {
      if(context.request.method == 'GET')
      {
            var form = serverWidget.createForm({
             title: "Netsuite Guru Test Form"
            });
            //========= if you need body field =========
            var bodyField = form.addField({
              id: 'custpage_ng_bodyfield',
              type: serverWidget.FieldType.Select,
              label: "DropDown Field",
              source: 'idOfListOrRecord'
            });
          //bodyField use this parameter to use property on this field

           //======== end if you need body field ========
          var ngSublist = form.addSublist({
              id: 'custpage_ng_sublist',
              type: serverWidget.SublistType.LIST,
              label: 'Nesuite Guru Sublist'
          });
         var field1 =  ngSublist.addField({
             id: 'custpage_field1',
             type: serverWidget.FieldType.TEXT,
             label: 'Field 1'
         });
// you can use field1 parameter to make it editable etc.
//========== start to set field value =============
 ngSublist.setSublistValue({
       id:'custpage_field1'
       line: 0
       value: 'Hello'          
    });

//NOTE: you can use for loop if you want to iterate through lines of record or search result.
// line always start from 0. if you try to enter 1 before 0 error will come.
// you can add as many line fields you want.
//========== end to set field value ==============
context.response.writePage(form);

       }
  }

return
{
  onRequest: onRequest
}
// ADD YOUR SUPPORTING FUNCTIONS HERE
 }
);


Please let me know if you have any question. Comment below.

Thanks
Netsuite Guru





 Download Netsuite Guru Android App
Follow Me on Linkedin
Our FB Page

Comments