I’m using a Suitelet to create an online form. Th...
# suitescript
j
I’m using a Suitelet to create an online form. The Suitelet writes out regular HTML for the form (it’s not a regular online form for a custom record or anything, I’m just capturing some information and then using the POSTed data to do some work in the background in our system). I’ve used similar methods in the past with success to get the data I want. What I’m doing for the first time here is that I have particular field that is a multiple select. The HTML for this field looks like this:
Copy code
<select name="platforms[]" id="platforms" multiple style="height: 110px;">
	<option value="1">Platform 1</option>
	<option value="2">Platform 2</option>
	<option value="3">Platform 3</option>
</select>
The form includes several other fields that are working as desired (dates, file uploads, single selects, etc). My issues is that upon submit on the form (I have a custom HTML button that simply calls
jQuery('#main_form').submit();
), only the FIRST selected value of the multiselect comes through in the
context.request.parameters;
object. All the other data from other fields comes through as expected. I’ve tried with and without the
[]
and still no luck. Any suggestions as to what I might be overlooking here?
a
when a multiselect field posts it uses the same param name repeatedly
platforms[]=1&platforms[]=2
NS's param object can't handle that cos its just key/value pairs which is why you're only getting one
are you using
multipart/form-data
? you said you had files?
NS will handle that in its request handler but they'll be under
context.request.files
Copy code
const selectedPlatforms = context.request.files['platforms'];
and yeah get rid of the
[]
cos eww 😛
j
yes, I’m using
multipart/form-data
and I can retrieve the files without issue.
So there’s no way to get all the selected values of the multiselect?
For now, I’m using
jQuery
to store the selected values (concatenated) in a hidden
<input>
field, which is working, but an annoying workaround.
a
the multiselect values don't ALSO show up in
request.files
yeah that way works too, just do it yourself essentially 🙂
👍 1
j
Thanks for confirming I’m not just missing something super obvious!
👍 1
a
i don't have an easy way to test it myself now, but I thought I remembered multiselect values also showing up in the files section? is that not true? can you just log context.request.files and see if there's
platforms
in there?
j
it’s not
👍 1
b
create an actual multiple select field and set it instead to see how netsuite handles multiselect fields. You will want to actually log the request body
you can use a library like qs if you want something standards compliant
s
NetSuite has custom handling for Multi-Selects where the use a single file txt field separated with Char(05) or similar char.
👍 1