jimijon
jimijon

Reputation: 2166

How to create a Custom Select List for a netsuite field?

I have a field on a custom record. The name of the field is reference_code.

I want to populate "reference_code" with my own dynamic list which would be presented as a drop down to the user.

How do I do this? I defined my field as Free-Text. Do I need to keep it hidden but then show it as a drop down before I load the form?

I thought this might do something:

nlapiInsertSelectOption('custrecord_rulereferencecode', code, code, false)

But I would need to convert the field to a select?

Upvotes: 2

Views: 10081

Answers (3)

Uma Kanth
Uma Kanth

Reputation: 5629

This can be done by giving a source to your drop-down menu. The source field accepts an internal id of a list. This internal id can be an in-built(provided by netSuite) or a custom list created by a user. For Eg: I have a custom list with an internal id '23' which has some list items in it, these can be populated in the drop down menu by the following syntax.

var start = function(request, response) { var form = nlapiCreateForm('Custom Form'); form.addField('custpage_selectfield', 'select', 'select a color', '23');//here 23 is the internal id of my list respnose.writePage(form); }

Here's the formor you could generate you own field's dynamically using the addSelectOption() function.

var start = function(request, response) { var form = nlapiCreateForm('Custom Form'); var myselectfield = form.addField('custpage_selectfield', 'select', 'select a color'); myselectfield.addSelectOption('1', 'Red');//Here 1, 2 and 3 are the id's myselectfield.addSelectOption('2', 'Green');//which are returned when the myselectfield.addSelectOption('3', 'Blue');//form is submitted respnose.writePage(form); }

Here's the Form

Upvotes: 3

jimijon
jimijon

Reputation: 2166

I solved this by creating two fields. One is created in the RecordType and will store the info. I set this as hidden. The next field, with the custom dropdown is added in user event. I then process data for my custom dynamic select list and add that to my added user event field.

Then in my change event, I set the record type field to the value selected in my dynamically added field.

Userevent

function userEventBeforeLoad(type, form, request){
  if(type == "edit"){
    form.addField('custpage_referencecode','select','Reference Code',null, null)
  }  
}

In my Client Script:

function clientFieldChanged(type, name, linenum){

if(name == 'custpage_referencecode'){
    //obtain the upper case value
    var codetext = nlapiGetFieldValue(name)

    //make sure it hasn't been set
    if (codetext != nlapiGetFieldValue('custrecord_rulereferencecode'))
    {
      nlapiSetFieldValue('custrecord_rulereferencecode', codetext );
    }
}

return true

}

Upvotes: 0

erictgrubaugh
erictgrubaugh

Reputation: 8847

Typically, instead of creating the field as Free-Text, you would first create a Custom List (Customization > Lists/Records/Fields > Lists > New) with all of your dropdown options.

Then you would create your field as a List/Record field and select your new Custom List as the "List/Record Type", as depicted below.

enter image description here

Upvotes: 3

Related Questions