How do I add a drop down list to my Suitelet form ...
# ask-stanley-ai
s
How do I add a drop down list to my Suitelet form using an existing custom list?
c
AI generated answer (using internal Slack threads):
To add a dropdown list to your Suitelet form using an existing custom list, you can use the
addField
method on the form object and set the
source
property to the internal ID of your custom list. Here is an example:
Copy code
javascript
var form = serverWidget.createForm({
    title: 'My Form'
});

var dropdown = form.addField({
    id: 'mydropdown',
    type: serverWidget.FieldType.SELECT,
    label: 'My Dropdown',
    source: 'customlist_my_custom_list' // replace with your custom list's internal ID
});
In this example,
serverWidget
is a reference to the
N/ui/serverWidget
module, which provides SuiteScript 2.0 API for creating and manipulating UI objects on the server side. If you want to dynamically change the options in the dropdown based on another field's value, you can use a client script. In the client script, you can use the
insertSelectOption
method to add new options to the dropdown. Here is an example:
Copy code
javascript
define(['N/currentRecord', 'N/log'],
    function(currentRecord, log) {
        function fieldChanged(context) {
            var record = context.currentRecord;
            var dropdown = record.getField({fieldId: 'mydropdown'});
            dropdown.insertSelectOption({value: 'Option1',text: 'alpha'});
        }
    }
);
In this example,
N/currentRecord
is a reference to the
N/currentRecord
module, which provides API for working with the current record in the client script. The
fieldChanged
function is a client script entry point function that is triggered when a field is changed. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.846465945
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.84558636
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.845091
Please provide your feedback on this answer.