Download Search Results as CSV files using Suitescript

The following script is designed for transforming Saved search results into a CSV file format. The provided code is equipped to manage scenarios where the search results exceed 4,000 results.

var savedSearch = search.load({ id: searchId });
var myPagedData = savedSearch.runPaged();

myPagedData.pageRanges.forEach(function(pageRange){
                    var myPage = myPagedData.fetch({index: pageRange.index});
                    myPage.data.forEach(function(result){
                        var rowData = [];
                        savedSearch.columns.forEach(function (column){
                            let resValue = checkForParameter(result.getText(column)) ? result.getText(column) : result.getValue(column)
                            rowData.push('"' + resValue + '"');
                        })
                        csvContent += rowData.join(',') + '\n';
                    })
                })

Leave a comment

Your email address will not be published. Required fields are marked *