Is there a way to uncheck/check this box on the sa...
# suitescript
n
Is there a way to uncheck/check this box on the saved search: SEND EMAIL ALERTS WHEN RECORDS ARE CREATED/UPDATED?
n
by script? Nope
n
😞
n
The search record cannot be updated by script using the record module. The search module allows you to add filters and columns to a search and that's all you can change by script. Not sure what you are trying to accomplish, stop automated emails?
n
Yes, I am trying to stop automated emails when sandbox is refreshed. Any suggestions?
n
Yes, you need to add a dummy filter to the saved searches so the criteria is impossible to meet. Something like this:
Copy code
var objSearchofSearches = search.create({
                type: search.Type.SAVED_SEARCH, filters: [{
                    name: 'sendscheduledemails',
                    operator: <http://search.Operator.IS|search.Operator.IS>,
                    values: ['T']
                }], columns: ['internalid']
            })
            var arrSearchResults = getAllSearchResults(objSearchofSearches);
            for (var x = 0; x < arrSearchResults.length; x++) {
                try {
                    var searchRecord = search.load({ id: arrSearchResults[x].id })
                    
                    var filtersArr = searchRecord.filters;
                    var objLastFilter = JSON.parse(JSON.stringify(filtersArr[filtersArr.length-1]));

                    //avoid updating a SS twice
                    if(objLastFilter.name == 'internalid' && objLastFilter.operator == 'anyof' && objLastFilter.values[0] == '-1'){
                        log.debug(stLogTitle, 'skipping: ' + arrSearchResults[x].id);
                        continue;
                    }
                    
                    filtersArr.push(search.createFilter({
                        name: 'internalid',
                        operator: <http://search.Operator.IS|search.Operator.IS>,
                        values: -1
                    }))
                    searchRecord.save();
                    log.audit(stLogTitle, 'Filtered: ' + arrSearchResults[x].id);
                } catch (error) {
                    log.error(stLogTitle, 'Failed udpating: ' + arrSearchResults[x].id);
                }
            }
That worked for 95% of my searches, I don't recall exactly but you might have issues if the search is private
n
Thanks a lot for this alternative solution. But this way there will be no results, correct?
As an alternate, I can also delete the searches, right? 😄
n
Manually yes but I don't think you can automate deletion of searches. This alternate solution would cause no results in the searches, but if you still want results on any specific search you can always manually update it.
If you find a better solution let me know! haha
this worked for my after a refresh, I had a massive number of searches created by users just to send emails
n
We have search.delete(options) API for deleting based on the results. But yes, as long as adding the dummy filter stops sending email in SB, I think that will work. Thanks a lot. I didn't think about it.
🙌 1