Anyone else seen this before? I have a multiselect...
# suitescript
m
Anyone else seen this before? I have a multiselect field in a suitelet and would like to default it to all options selected. I thought I should be able to do
field.defaultValue = field.getSelectOptions().map((option) => option.value)
, but as soon as I call
field.getSelectOptions
setting a default value stops working. Workaround is to create a second hidden field and get the options from that field to set on the displayed field netsuite
s
I don't recall what
defaultValue
is supposed to be but I presume a single value? The code you show would assign an array to
defaultValue
j
It’s a string so yeah, probably comma-separated string is the way to go
m
Official docs say just a string, but TS typings are
string|string[]
. Passing an array of strings works, but not after calling
field.getSelectOptions()
This works:
Copy code
const field = form.addField({
  type: serverWidget.FieldType.MULTISELECT,
  id: "custpage_multiselect_field",
  label: "Test Field",
  source: "custlist_my_custom_list",
});

field.defaultValue = ["1", "2", "3"];
This does not work:
Copy code
const field = form.addField({
  type: serverWidget.FieldType.MULTISELECT,
  id: "custpage_multiselect_field",
  label: "Test Field",
  source: "custlist_my_custom_list",
});

field.getSelectOptions();

field.defaultValue = ["1", "2", "3"];
s
If this is a custom suitelet, sounds like a job for HTML rather than wrangling inconsistent behavior of the serverWidget apis
m
We've had this debate before, but I'm not running to custom html for a simple 5 field suitelet and if I would avoid any inconsistent API's that would rule out pretty much all of NetSuite lol
s
a simple approach is to use basically plain HTML for the form, served up by suitelet GET, and post back to the Suitelet like you would normally. In other words, you could just drop the clunky UI generation but keep the rest of the suitelet. It also lets you actually see what you're working with.
I guess my point is, didn't mean to suggest something heavy like SPA/framework
👍 1