Show a popup window in NetSuite with a Checkbox field

NetSuite uses the ExtJS library for a variety of purposes including showing popup windows for alerts and confirmations. We can make use of this to tailor this popup window for our own uses cases which would otherwise couldn’t be met using the standard ‘N/ui/dialog Module’
Note : We are using the ExtJS library which NetSuite used for building their own popup/modal/dialog purpose. If NetSuite decides to upgrade this library or change this to another library, it may break the existing scripts if we use the ExtJS library directly.

Show a popup window in NetSuite with a Checkbox field
The following code snippet is for the scenario defined below :
The popup window should have a title and a message. The popup should have an option like a checkbox field. Upon submission, we should retrieve whether the checkbox is checked by the user.

To create a popup window in NetSuite using the ExtJS library with a title, message, and a checkbox field, you can use the following code:

// Create a function to show the popup window
function showPopupWindow() {
  // Create a checkbox field
  var checkboxField = new Ext.form.Checkbox({
    fieldLabel: 'Check me'
  });

  // Create the submit button
  var submitButton = new Ext.Button({
    text: 'Submit',
    handler: function() {
      // Retrieve the checkbox value
      var isChecked = checkboxField.getValue();
      
      // Perform any desired actions with the checkbox value
      console.log('Checkbox is checked:', isChecked);
      
      // Close the popup window
      popupWindow.close();
    }
  });

  // Create the popup window
  var popupWindow = new Ext.Window({
    title: 'Do you want to',
    layout: 'form',
    items: [checkboxField],
    buttons: [submitButton]
  });

  // Show the popup window
  popupWindow.show();
}

// Call the function to show the popup window
showPopupWindow();

This code will create a popup window with a title, a checkbox field labeled “Check me,” and a submit button. Upon clicking the submit button, the state of the checkbox (whether it is checked or not) will be retrieved, and you can perform any desired actions with this value.

Leave a comment

Your email address will not be published. Required fields are marked *