Using a ClientScript for a SuiteLet what is the be...
# suitescript
d
Using a ClientScript for a SuiteLet what is the best method to add/remove options for a select field? I am attempting to use currentRecord.getField but I seem to be having some troubles… probably something to do with getting the proper ID for the field.
b
best method is using getting the field using CurrentRecord.getField and using Field.insertSelectOptions and Field.removeSelectOptions
you can try sharing your code, but generally you choose the ids of fields in a suitelet form
d
I have been trying that
Copy code
currentRecord.getField({fieldId: 'finishing'}).removeSelectOption({
        value: null,
      });
message has been deleted
and this is the error that gets thrown every time I try to touch that field
b
what does the setup for that field look like in the suitelet
d
Copy code
var finishingOptionField = form.addField({id: 'finishing', type: 'select', label: 'Finishing:', container: 'grp_finishing'});
        finishingOptionField.layoutType = ui.FieldLayoutType.NORMAL;
        finishingOptionField.isMandatory = true;
b
im assuming the error occurs simply with currentRecord.getField({fieldId: 'finishing'})
d
no
if I remove the removeOption or insertOption there is no error
b
meh
sounds weird
assume netsuite is being weird and just prefix your ids with custpage
so use custpage_finishing as your id
d
ok will try
failboat 😱
when I using
Copy code
finishing
it definitely pulls the field
b
on both the suitelet and client script?
you should at least get the same error
d
I am trying all this from CS… now I am trying to test in console
message has been deleted
what else is interesting is that when I do this
Copy code
field.removeSelectOption({
    value: 1,
});
it works
ok I am going to be royally pissed if I just spend the last 1/2 hour racking my head on this for what I just found.
b
you should always get an error trying to remove null
although probably not the invalid ui object error
the ui object error suggests that netsuite is having trouble finding the field metadata, which is why i suggested using the custpage prefix
d
which is strange because it works in console
and removeSelectOption({value: null}) is documented
message has been deleted
I am wondering if it is because I am doing this in pageInit that there is some problem
I guess another way to handle this is to simply dump the current record fields and see whats in the goodie bag
b
are you sure you changed the id correctly?
the following works for me
Copy code
/**
 * @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
/**
 * @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
        });
    }
  };
});
there arent any select options to remove, but there is no error and you can add options afterwards
d
so change all the field ids to precurse with custpage_?
well let me try it
šŸ’¢
WTF
@battk thanks
b
what did you do an hour ago when i told you to use custpage_finishing as the id
d
@battk I only changed that field… which didn’t work
but when I changed ALL fields it worked