How can I have an alert pop up when no results are...
# suitescript
p
How can I have an alert pop up when no results are found in a search? I thought I could use if the variable that equals the result.getValue is blank then show the alert but that is not working.
Copy code
mySearch.run()
               .getRange(0,1000)
               .forEach(function (result) {
             
                  var myResultId = result.getValue({name: "internalid" });
                  if (myResultId == "") {
                      dialog.alert({
                          message: 'No results found'
                      })
                  }
b
there is a difference between no results and a result with no internal id
t
@battk Will there be any result with no internal id ?
c
When you run the search, search results has a "count" property that tells you the # of results.
b
there are plenty of ways to solve the problem
💯 1
the more obvious ones dont have you trying to do everything in one chained statement
p
thanks @creece using your tip I solved my problem by doing the below
Copy code
var searchResultCount = mySearch.runPaged().count;
             console.log(searchResultCount);
             if (searchResultCount == 0) {
                 dialog.alert({
                     message: 'No results.'
                 })
             }
             mySearch.run()
Now whether or not this is the correct way to do it I am not sure but it achieved my goal.
b
i will recommend that you use the pagedData return by mySearch.runPaged() to fetch your search results
any time that you dont use the each function of a data set should be replaced by a paged search