can i add a filter here to only get me the account...
# ask-stanley-ai
n
can i add a filter here to only get me the accounts of a certain type var accountSelectField = form.addField({ id: 'custpage_account_select', type: serverWidget.FieldType.SELECT, label: 'Account', container: "mainInfo", source: 'account' });
c
AI generated answer (using internal Slack threads):
Based on the conversations, it appears that you cannot directly add a filter to the
source
attribute of the
addField
method in SuiteScript. The
source
attribute is used to populate the select field with values from a specific record or list, but it does not support filtering. However, there are alternative ways to achieve the desired result: 1. You can create a search to retrieve the accounts of a certain type, and then loop through the results to add them as select options using the
addSelectOption
method. Here is a sample code:
Copy code
javascript
var accountField = form.addField({
    id: 'custpage_account_select',
    type: serverWidget.FieldType.SELECT,
    label: 'Account',
    container: "mainInfo"
});

var accountSearch = search.create({
    type: 'account',
    filters: [
        ['type', 'anyof', 'Bank']
    ],
    columns: ['internalid', 'name']
});

accountSearch.run().each(function(result) {
    accountField.addSelectOption({
        value: result.getValue('internalid'),
        text: result.getValue('name')
    });
    return true;
});
2. Another approach is to add all the options first by specifying a
source
in
addField
, and then remove the unwanted options using the
removeSelectOption
method. However, this method might not be efficient if there are a large number of options to remove. ****** 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.881703854
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.857878506
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.837853134
Please provide your feedback on this answer.