Friday, October 5, 2018

Dynamically Source the Entity List into a Suitelet Select Field


Sample code provided below allows a Suitelet to have Select field source the Entity List from another field. In this scenario the list is being retrieved from the Calendar Event Record

The list loads these Record Types: 

Customers
Partners
Projects

Vendors


function suiteletEntityList(request, response)

{

      if (request.getMethod() == 'GET') {

            //Create a Form as the container

            var form = nlapiCreateForm('frm_entity_listing');

            var fld = form.addField('entitylist','select','Entity List',null);

           

            //Create a calendar event record

            //Retrieve the list from the company field using the nlobjField.getSelectOptions()

            var eventRec = nlapiCreateRecord('calendarevent');

            var companyField = eventRec.getField('company');

            var companies = companyField.getSelectOptions();

           

            //Load the company list into the select field using the nlobjField.addSelectOption()

            for (var i in companies) {

                  fld.addSelectOption(companies[i].getId(), companies[i].getText());

            }

           

            //Write the form on the Suitelet Page

            response.writePage(form);

      }

}

1 comment:

  1. You can directly use -9 to add entity list fields
    e.g.(SuiteScript 2.0):

    var entityFld = form.addField({
    id: 'custpage_entity',
    type: serverWidget.FieldType.SELECT,
    label: 'Entity List',
    source: -9
    });

    ReplyDelete