2 questions. 1. Can I sort the options in a Multi...
# suitescript
a
2 questions. 1. Can I sort the options in a Multiselect Field? 2. Can I change the multiselect options from scroll and highlighting to adding in a text box?
e
1. If it's a custom list - on the custom list record there is a "Show Options in:" setting that you can choose "The Order Entered". Then you drag n drop the values in the sublist to the order you want.
a
I add each option manually.
e
I would create an array of objects for the options, then sort them, then loop through to add them to the select field.
Copy code
const selectOptions = [{
    text: "Select B",
    value: "select_b"
}, {
    text: "Select C",
    value: "select_c"
}, {
    text: "Select A",
    value: "select_A"
}];

// From: <https://stackoverflow.com/questions/21131224/sorting-json-object-based-on-attribute>
function sortByKey(array, key) {
    return array.sort(function (a, b) {
        var x = a[key];
        var y = b[key];
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    });
}

const sortedOptions = sortByKey(selectOptions, 'text');

sortedOptions.forEach(option => {
    yourSelectField.addSelectOption({
        value: option.value,
        text: option.text,
    })
});
(.....this is all assuming you were talking about in a suitelet)
a
It is. My sort function wasn't working properly.