繁体   English   中英

将 Select 选项添加到 NetSuite 中 HTML Suitelet 的下拉字段中

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

因此,在常规的 NetSuite Suitelet 表单中,我们使用以下 API(在 SuiteScript 2.0 中)添加“选择”字段:

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

由于上述 Select 字段的“来源”是“客户”,因此该字段将显示“客户”列表作为其选项。

但是,就我而言,我正在构建一个HTML Suitelet 表单(而不是常规的 Suitelet 表单)。 因此,下面是我在表单中添加“选择”(即下拉)字段的方式。

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.

因此,如何在 select 字段(在 HTML Suitelet 中)中添加(源)客户列表作为选项?

欢迎任何建议/替代方案。 并感谢您花时间经历同样的事情。

除非“客户”已经是 ID 和名称的组合,否则我认为您必须获取每个客户 ID 和名称。 然后将它们分别添加为 html 格式的选项...

//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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM