Anand Rajaram
Anand Rajaram

Reputation: 41

Adding Select Options to a Drop Down field in a HTML Suitelet in NetSuite

So in a regular NetSuite Suitelet form, we add a "Select" field using the following API (in SuiteScript 2.0):

var selectField = form.addField({
    id : 'custpage_selectfield',
    type : serverWidget.FieldType.SELECT,
    label : 'Select',
    source: customer       
});

And since the "source" of the above Select field is "customer", the field would display the list of "Customers" as its options.

However in my case, I am building a HTML Suitelet Form (and not a regular Suitelet form). Hence, below is the way I am adding the "select" (i.e. drop down) field in the form.

var htmlStr = '';    // constructing the HTML string.
htmlStr += '<html>';
htmlStr +=       '<body>';
htmlStr +=           '<select id="customerSelect">';
htmlStr +=               '<option value=""></option>';

                  // And I would like to add the source-list of customers, as options in this select field

htmlStr +=           '</select>';   // closing the select tag
htmlStr +=     '</body>';
htmlStr += '</html>';

context.response.write(htmlStr);    // to write and display the HTML form.

Hence, how do I add the (source) list of customers as options in the select field (in HTML Suitelet)?

Any suggestions/alternatives are welcome. And thank you for your time in going through the same.

Upvotes: 0

Views: 2365

Answers (1)

Martha
Martha

Reputation: 764

unless "customer" is already a combination of ids and names, I think you'll have to obtain each customer id and name. Then add them each as an option in html format...

//empty string to hold all options
var optionValues = '';

//search for customers, return at least Name and Internal ID
var customerSearchObj = search.create({
  type: "customer",
  filters:[
    ["isinactive","is","F"]
  ],
  columns:[
    search.createColumn({
      name: "internalid",
      label: "Internal ID"
    }),
    search.createColumn({
      name: "entity",
      label: "Name"
    })
  ]
});

//for each result add an option for the select field
customerSearchObj.run().each(function(result){// .run().each has a limit of 4,000 results
  var internalid = result.getValue({
    name: 'internalid'
  });
  var name = result.getText({
    name: 'entity'
  });

  //create string version of select field result and add to major string or an array and array.toString later
  var tempString = '<option value="' +internalid+ '">' +name+ '</option>';
  optionValues += tempString;
  return true;
});

var htmlStr = '';
htmlStr += '<html>';
htmlStr +='<body>';
htmlStr +='<select id="customerSelect">';
htmlStr +=optionValues;
htmlStr +='</select>';
htmlStr +='</body>';
htmlStr += '</html>';

context.response.write(htmlStr);

Upvotes: 1

Related Questions