Luis
09/05/2024, 12:45 PMfunction updateSearch(existingSearch, billIds) {
log.debug("Updating existing search for search:", existingSearch)
var loadedSearch = search.load({
id: existingSearch
});
loadedSearch.filters = [
search.createFilter({
name: 'internalId',
operator: search.Operator.ANYOF,
values: billIds
})
];
loadedSearch.save();
}
but I'm getting:
TypeError: Cannot read property "values" from null
I verified and the billIds array is properly populated, what could be causing this issue?Celigo AI
09/05/2024, 12:45 PMAI generated answer (using internal Slack threads):The error you're encountering,
TypeError: Cannot read property "values" from null
, is likely due to the fact that you're trying to directly assign a new filter to the filters
property of a loaded search.
In SuiteScript, when you load a saved search, the filters
property is read-only. You cannot directly assign a new filter to it. Instead, you should create a new array of filters and then use the filterExpression
property to apply these filters to your search.
Here's how you can modify your function to do this:
javascript
function updateSearch(existingSearch, billIds) {
log.debug("Updating existing search for search:", existingSearch)
var loadedSearch = search.load({
id: existingSearch
});
var newFilters = [
search.createFilter({
name: 'internalId',
operator: search.Operator.ANYOF,
values: billIds
})
];
loadedSearch.filterExpression = newFilters;
loadedSearch.save();
}
In this modified function, we're creating a new array of filters (in this case, just one filter) and then using the filterExpression
property to apply these filters to the loaded search. This should resolve the error you're seeing.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
09/05/2024, 12:45 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.822740674
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.821677685
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.816440344
Celigo AI
09/05/2024, 12:45 PM