Hi there! I have created a Netsuite Saved Search w...
# ask-stanley-ai
d
Hi there! I have created a Netsuite Saved Search with ID customsearch1882. I would like to write a SuiteScript that runs once a day at 5am and runs this report. If the record count in the report is larger than 500 records, I would like the script to send an e-mail. The e-mail should be sent to the addresses flip@flop.com and tip@top.com, the subject of the e-mail should be "High Amount of NetSuite Production SOAP WS Calls Last Night", the body should contain text "Last night over 500 Netsuite SOAP WS calls were made on Production". Give me a step by step guide on how to do this.
c
AI generated answer (using internal Slack threads):
Here is a step-by-step guide on how to create a SuiteScript that runs a Saved Search and sends an email if the record count is larger than 500: 1. Create a Scheduled Script: Go to Customization > Scripting > Scripts > New. Select 'Scheduled Script' as the script type. Upload your .js file and give your script a name and ID. 2. Write the SuiteScript: In your .js file, you will need to use the
nlapiSearchRecord
function to run the Saved Search, and the
nlapiSendEmail
function to send the email. Here is a sample script:
Copy code
javascript
function scheduled(type) {
    var search = nlapiLoadSearch(null, 'customsearch1882');
    var resultSet = search.runSearch();
    var results = resultSet.getResults(0, 1000);
    if (results.length > 500) {
        var emailSubject = 'High Amount of NetSuite Production SOAP WS Calls Last Night';
        var emailBody = 'Last night over 500 Netsuite SOAP WS calls were made on Production';
        var recipients = ['<mailto:flip@flop.com|flip@flop.com>', '<mailto:tip@top.com|tip@top.com>'];
        nlapiSendEmail(-5, recipients, emailSubject, emailBody);
    }
}
3. Set the Script Deployment: After creating the script record, you will be redirected to the script deployment page. Set the status to 'Scheduled', and set the 'Start Time' to 5am. Make sure the 'Recurrence' is set to 'Daily'. 4. Save and Test: Save the script deployment and test it to make sure it works as expected. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.858428359
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.851278365
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.848180652
Please provide your feedback on this answer.
Thank you for your feedback