I'm trying to create a filter for a search using s...
# ask-stanley-ai
l
I'm trying to create a filter for a search using suitescript using this code
Copy code
search.createFilter({
            name: 'entityid',
            operator: search.Operator.HASKEYWORDS,
            values: customerIds
        })
where customerIds is an array of strings, but apparently this filter name does not accept this operator and an array as values, can we refactor to use a formula or a query in this filter so that works with arrays?
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that you are trying to use the
HASKEYWORDS
operator with an array of values on a field that does not support this operator. One way to handle this situation is to create separate filters for each value in the array and use the
OR
operator to combine them. Here is an example of how you can do this:
Copy code
javascript
var filters = customerIds.map(function(id) {
    return search.createFilter({
        name: 'entityid',
        operator: <http://search.Operator.IS|search.Operator.IS>,
        values: id
    });
});
filters = search.createFilter({
    name: 'entityid',
    join: 'OR',
    operator: search.Operator.ANYOF,
    values: filters
});
Another approach is to use a formula that uses the
IN
condition. Here is an example:
Copy code
javascript
var filter = search.createFilter({
    name: 'formulanumeric',
    operator: search.Operator.EQUALTO,
    values: 1,
    formula: "CASE WHEN {entityid} IN ('" + customerIds.join("','") + "') THEN 1 ELSE 0 END"
});
Please note that the
IN
condition is case sensitive and it only works with text fields. If
entityid
is a numeric field, you might need to convert it to a text field in the formula. ****** 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.880933344
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.859306037
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.857938886
Please provide your feedback on this answer.