RE: 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,
});

                
emericas1 Rookie Asked on January 17, 2023 in SuiteScript.
Add Comment
1 Answers

Hi,

You have two choices here:

  1. Add a submit button and you will see the selection POSTed back to the Suitelet.
  2. Add a Client Script with a fieldChanged endpoint to handle the change dynamically.

Let me know if you need any further details.

Thanks,

Chris

Intermediate Answered on January 24, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.