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. The report is of type SOAP Web Services Operations. 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 new SuiteScript of type 'Scheduled Script'. You can do this by navigating to
Customization > Scripting > Scripts > New
, and then selecting 'Scheduled Script' from the list. 2. In the script file, you will need to use the
N/search
module to load and run your Saved Search. Here is a sample code snippet:
Copy code
javascript
var search = require('N/search');

function execute(context) {
    var mySearch = search.load({
        id: 'customsearch1882'
    });

    var resultSet = mySearch.run();
    var results = resultSet.getRange({
        start: 0,
        end: 1000
    });

    if (results.length > 500) {
        sendEmail();
    }
}
3. In the
sendEmail
function, use the
N/email
module to send an email. Here is a sample code snippet:
Copy code
javascript
var email = require('N/email');

function sendEmail() {
    email.send({
        author: -5, // -5 is the internal ID for the system user
        recipients: ['<mailto:flip@flop.com|flip@flop.com>', '<mailto:tip@top.com|tip@top.com>'],
        subject: 'High Amount of NetSuite Production SOAP WS Calls Last Night',
        body: 'Last night over 500 Netsuite SOAP WS calls were made on Production'
    });
}
4. Deploy the script and set the schedule. You can do this by navigating to
Customization > Scripting > Script Deployments > New
. Set the 'Start Time' to 5am and the 'Interval' to 'Daily'. Please note that the above code snippets are just examples and may need to be adjusted to fit your specific needs. ****** 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.852972448
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.85217452
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847050726
Please provide your feedback on this answer.