How do I apply this filter to the search before sa...
# ask-stanley-ai
l
How do I apply this filter to the search before saving?
Copy code
var loadedSearch = search.load({
        id: searchId
    });

    var filter = search.createFilter({
        name: 'formulanumeric',
        operator: search.Operator.EQUALTO,
        values: 1,
        formula: "CASE WHEN {entityid} IN ('" + customerIds.join("','") + "') THEN 1 ELSE 0 END"
    });

    loadedSearch.filters = []; // what should I do here?

    loadedSearch.save();
c
AI generated answer (using internal Slack threads):
To apply the filter to the search before saving, you should push the filter into the filters array of the loaded search. Here is how you can do it:
Copy code
javascript
var loadedSearch = search.load({
    id: searchId
});

var filter = search.createFilter({
    name: 'formulanumeric',
    operator: search.Operator.EQUALTO,
    values: 1,
    formula: "CASE WHEN {entityid} IN ('" + customerIds.join("','") + "') THEN 1 ELSE 0 END"
});

loadedSearch.filters.push(filter);

loadedSearch.save();
In the above code,
loadedSearch.filters.push(filter);
is used to add the created filter to the filters array of the loaded search. After this, when you save the search, the filter will be applied. ****** 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.8413288
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.836599767
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.836417913
Please provide your feedback on this answer.