Scenario
There are instances where users want to receive an email of a search results in CSV file for their customers via scheduled script.
Solution
function sendEmail(type){ //Creating Search Filters var filters = []; filters[0] = new nlobjSearchFilter('lastname', null, 'startswith', 's'); //Creating Search Columns var columns = []; columns[0] = new nlobjSearchColumn('internalid'); columns[1] = new nlobjSearchColumn('email'); columns[2] = new nlobjSearchColumn('phone'); var search = nlapiSearchRecord('customer', null, filters, columns); var contents = ''; if(search){ for (var x = 0; x < search.length; x++){ var internalID = search[x].getValue('internalid'); var email = search[x].getValue('email'); var phone = search[x].getValue('phone'); contents += internalID + ',' + email + ',' + phone + '\n'; } var file = nlapiCreateFile('results.csv', 'CSV', contents); nlapiSendEmail('', '', 'Email Subject', 'Email Body', null, null, null, file); } }
Note: Please see SuiteAnswers articles - 29246 SuiteScript 1.0 Script Creation, Deployment, and Logging for steps on how to run a script in NetSuite.