Introduction
Once you have a logging dashboard (see Blog 74), the next step is proactive alerting.
Instead of manually checking logs, your team should get instant alerts when an integration fails β reducing downtime and improving response time.
In this guide, youβll:
- Create a Scheduled Script that checks for failed logs.
- Send Email alerts to admins.
- Post Slack notifications via webhook.
π§± 1. Pre-Setup
- Use the custom record
customrecord_integration_log
from Blog 74. - Make sure failures are logged with
custrecord_status = "Failed"
. - Store configuration in script parameters:
- Email recipient(s)
- Slack Webhook URL
βοΈ 2. Scheduled Script β Check & Notify
/**
* @NApiVersion 2.1
* @NScriptType ScheduledScript
*/
define(['N/search', 'N/email', 'N/runtime', 'N/https', 'N/log'],
(search, email, runtime, https, log) => {
const execute = () => {
const failedLogs = getFailedLogs();
if (failedLogs.length === 0) {
log.audit('No Failures', 'All integrations running fine');
return;
}
const message = formatMessage(failedLogs);
sendEmailAlert(message);
sendSlackAlert(message);
log.audit('Alerts Sent', `${failedLogs.length} failure(s) reported`);
};
const getFailedLogs = () => {
const results = [];
const s = search.create({
type: 'customrecord_integration_log',
filters: [
['custrecord_status', 'is', 'Failed'],
'AND',
['created', 'onorafter', 'today']
],
columns: ['custrecord_source_system', 'custrecord_message', 'custrecord_reference_id']
}).run().getRange({ start: 0, end: 10 });
s.forEach(r => results.push({
source: r.getValue('custrecord_source_system'),
msg: r.getValue('custrecord_message'),
ref: r.getValue('custrecord_reference_id')
}));
return results;
};
const formatMessage = (list) => {
let msg = `π¨ *NetSuite Integration Alert* π¨\n\n*Failed Logs Today:*\n`;
list.forEach((e, i) => {
msg += `${i+1}. Source: ${e.source}\n Message: ${e.msg}\n Ref: ${e.ref}\n\n`;
});
return msg;
};
const sendEmailAlert = (message) => {
const recipients = runtime.getCurrentScript().getParameter({ name: 'custscript_email_recipients' }).split(',');
email.send({
author: runtime.getCurrentUser().id,
recipients: recipients,
subject: 'NetSuite Integration Failure Alert',
body: message
});
};
const sendSlackAlert = (message) => {
const url = runtime.getCurrentScript().getParameter({ name: 'custscript_slack_webhook' });
if (!url) return;
https.post({
url: url,
body: JSON.stringify({ text: message }),
headers: { 'Content-Type': 'application/json' }
});
};
return { execute };
});
β How It Works:
- Runs daily or hourly.
- Searches for any failed logs created today.
- Sends formatted alerts to both Email and Slack.
π¬ 3. Slack Webhook Setup
- In Slack β Apps & Integrations β Incoming Webhooks
- Click Add to Slack β Choose channel (e.g., #netsuite-alerts)
- Copy the Webhook URL and store it in a NetSuite script parameter.
π§ 4. Example Email Notification
Subject: β NetSuite Integration Failure Alert
Body:
π¨ NetSuite Integration Alert π¨
Failed Logs Today:
1. Source: Shopify
Message: Error creating Sales Order - invalid item ID
Ref: 30022
2. Source: Salesforce
Message: Missing Customer ID
Ref: 10012
π² 5. Example Slack Message
Preview in Slack:
π¨ NetSuite Integration Alert π¨
*Failed Logs Today:*
1οΈβ£ Shopify β Error creating Sales Order - invalid item ID
2οΈβ£ Salesforce β Missing Customer ID
You can also enhance Slack messages with emojis, attachments, or buttons to open NetSuite directly.
π§ 6. Enhancements & Options
Feature | Description |
---|---|
Frequency Control | Schedule every 30 min or hourly via deployment |
Log Deduplication | Mark notified logs with a βNotifiedβ checkbox |
Error Threshold | Only alert if count > X failures |
Severity Levels | Group by integration type or error severity |
Slack Threads | Post replies under a daily alert message for clean threading |
π 7. Security & Access
- Limit script execution to Administrator / Integration roles.
- Store Slack URLs and recipient lists in encrypted script parameters.
- Avoid logging sensitive data (e.g., tokens, passwords).
β 8. Best Practices
Tip | Benefit |
---|---|
Run script on a schedule | Near real-time notifications |
Combine Email + Slack | Redundant alert channels |
Use short messages | Prevent truncated notifications |
Archive old logs weekly | Maintain clean monitoring data |
Integrate with dashboard (Blog 74) | Full visibility of alerts + trends |
Conclusion
This automated alert system transforms integration monitoring from reactive to proactive.
By combining Email and Slack notifications, you ensure the right people are alerted immediately when something fails β keeping operations smooth and customers happy.
Learn more about various NetSuite Integration
Discover more from The NetSuite Pro
Subscribe to get the latest posts sent to your email.
Leave a Reply