如何为 netsuite 字段创建自定义 Select 列表?
How to create a Custom Select List for a netsuite field?
我在自定义记录上有一个字段。字段的名称是 reference_code.
我想用我自己的动态列表填充 "reference_code",该列表将作为下拉列表显示给用户。
我该怎么做?我将我的字段定义为自由文本。我是否需要将其隐藏,然后在加载表单之前将其显示为下拉列表?
我认为这可能会有所作为:
nlapiInsertSelectOption('custrecord_rulereferencecode', code, code, false)
但我需要将字段转换为 select?
通常,您可以先创建一个自定义列表(,而不是将字段创建为自由文本自定义 > Lists/Records/Fields > 列表 > 新建) 以及所有下拉选项。
然后您将创建您的字段作为 List/Record 字段和 select 您的新自定义列表作为 "List/Record Type",如下所示.
我通过创建两个字段解决了这个问题。一个是在 RecordType 中创建的,将存储信息。我将其设置为隐藏。下一个带有自定义下拉列表的字段被添加到用户事件中。然后,我为我的自定义动态 select 列表处理数据,并将其添加到我添加的用户事件字段中。
然后在我的更改事件中,我将记录类型字段设置为 selected 在我动态添加的字段中的值。
用户事件
function userEventBeforeLoad(type, form, request){
if(type == "edit"){
form.addField('custpage_referencecode','select','Reference Code',null, null)
}
}
在我的客户端脚本中:
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
}
这可以通过为下拉菜单提供来源来完成。源字段接受列表的内部 ID。此内部 ID 可以是内置的(由 netSuite 提供)或用户创建的自定义列表。例如:我有一个内部 ID 为“23”的自定义列表,其中包含一些列表项,可以通过以下语法在下拉菜单中填充这些项。
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);
}
或者您可以使用 addSelectOption() 函数动态生成您自己的字段。
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);
}
我在自定义记录上有一个字段。字段的名称是 reference_code.
我想用我自己的动态列表填充 "reference_code",该列表将作为下拉列表显示给用户。
我该怎么做?我将我的字段定义为自由文本。我是否需要将其隐藏,然后在加载表单之前将其显示为下拉列表?
我认为这可能会有所作为:
nlapiInsertSelectOption('custrecord_rulereferencecode', code, code, false)
但我需要将字段转换为 select?
通常,您可以先创建一个自定义列表(,而不是将字段创建为自由文本自定义 > Lists/Records/Fields > 列表 > 新建) 以及所有下拉选项。
然后您将创建您的字段作为 List/Record 字段和 select 您的新自定义列表作为 "List/Record Type",如下所示.
我通过创建两个字段解决了这个问题。一个是在 RecordType 中创建的,将存储信息。我将其设置为隐藏。下一个带有自定义下拉列表的字段被添加到用户事件中。然后,我为我的自定义动态 select 列表处理数据,并将其添加到我添加的用户事件字段中。
然后在我的更改事件中,我将记录类型字段设置为 selected 在我动态添加的字段中的值。
用户事件
function userEventBeforeLoad(type, form, request){
if(type == "edit"){
form.addField('custpage_referencecode','select','Reference Code',null, null)
}
}
在我的客户端脚本中:
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
}
这可以通过为下拉菜单提供来源来完成。源字段接受列表的内部 ID。此内部 ID 可以是内置的(由 netSuite 提供)或用户创建的自定义列表。例如:我有一个内部 ID 为“23”的自定义列表,其中包含一些列表项,可以通过以下语法在下拉菜单中填充这些项。
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);
}
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);
}