Suitelet Select field values are not selectable af...
# ask-stanley-ai
a
Suitelet Select field values are not selectable after using field.addSelectOption method to add select options.
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that the issue is related to the use of the
addSelectOption
method in SuiteScript. When you add select options to a sublist field in a Suitelet, it seems that the options are added for all lines, not just the current one. This can cause issues when the options for a field on one line are dependent on the value of another field on the same line. One solution suggested in the conversations is to not filter the select options, but instead validate the selected option either on
validateField
or
validateLine
, depending on what works best for your workflow. This way, you can ensure that the selected option is valid without affecting the options on other lines. Another solution is to use the
getField
method of the
currentRecord
object to get the field, and then use the
insertSelectOptions
and
removeSelectOptions
methods to add and remove options. However, it seems that there might be some issues with getting the correct ID for the field. One suggestion is to prefix your field IDs with
custpage_
. Here is a code sample from the conversations:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 * @NModuleScope SameAccount
 */
define(["N/ui/serverWidget", "N/url", "N/search"], function(serverWidget) {
  return {
    onRequest: function(context) {
      log.debug("context", context);
      var request = context.request;
      var response = context.response;

      var form = serverWidget.createForm({ title: "Hi David" });

      var finishingOptionField = form.addField({
        id: "custpage_finishing",
        type: "select",
        label: "Finishing"
      });
      finishingOptionField.layoutType = serverWidget.FieldLayoutType.NORMAL;
      finishingOptionField.isMandatory = true;
      
      form.clientScriptModulePath = '/SuiteScripts/client.js'

      response.writePage(form);
    }
  };
});
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope Public
 */
define(["N/currentRecord"], function(currentRecord) {
  return {
    pageInit: function(context) {
      context.currentRecord
        .getField({ fieldId: "custpage_finishing" })
        .removeSelectOption({
          value: null
        });
    }
  };
});
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.828540146
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.827627
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.824049771
Please provide your feedback on this answer.