How do I get Select field values?
I have a Suitelet page where I created a few form fields. I have these Select fields sourcing from records. What I would like to do is store the Select value in a variable so I can pass it into a Saved Search I am running elsewhere in the script. How do I store a Select choice in a var the Suitescript way? Thanks in advance!
code snippet:
const onRequest = (scriptContext) => {
if (scriptContext.request.method === “GET”) {
// this creates the form for the page
let form = serverWidget.createForm({
title: “Disconnect Inventory Page”,
});
// Select Site Location Form
let locationForm = form.addField({
id: “custrecord_ec_site_identifier”,
type: serverWidget.FieldType.SELECT,
label: “Select Site Location”,
source: “Location”,
});
locationForm.isMandatory = true;
// Customer Select
let customerSelect = form.addField({
id: “custrecord_customer_select”,
type: serverWidget.FieldType.SELECT,
label: “Select Customer”,
source: “Customer”,
});
customerSelect.isMandatory = true;
// Inventory Type Select – Cabinet or Power Circuit
let invTypeSelect = form.addField({
id: “custrecord_inv_type_select”,
type: serverWidget.FieldType.SELECT,
label: “Select Inventory Type”,
});
invTypeSelect.isMandatory = true;
// ! TESTING FOR GETTING SELECT VALUES
var currentSiteSelection = scriptContext.request.parameters.custrecord_ec_site_identifier;
log.debug({
title: “currentSiteSelection”,
details: currentSiteSelection,
});
Hi,
You have two choices here:
- Add a submit button and you will see the selection POSTed back to the Suitelet.
- Add a Client Script with a fieldChanged endpoint to handle the change dynamically.
Let me know if you need any further details.
Thanks,
Chris