The purpose of this task is to enhance operational efficiency and improve customer engagement by enabling automated voice communication directly from the Lead record in NetSuite. By adding a custom button that triggers a SuiteScript REST API call to the Voicebot Auto Call Bridging API, users can instantly initiate automated calls without leaving the CRM interface. This reduces manual effort, speeds up lead follow-ups and ensures timely communication, ultimately increasing conversion rates and improving the overall customer experience.
Here, We are going to add a custom button in the Lead record in NetSuite. when clicked, it will trigger a SuiteScript REST API call to your Voicebot Auto Call Bridging API.
Here’s a step-by-step approach with example code :
STEPS :
- Add a custom button in the Lead record (via User Event script or Form customization).
- On button click, trigger a Client Script function.
- The Client Script will call a Suitelet or directly use https.post (via N/https in SuiteScript 2.x) to send the API request.
- Client Script cannot make external HTTP requests directly (security restriction).
- That’s why we use a Suitelet/RESTlet as a backend service to handle the call.
IMPLEMENTATION :
User Event Script (Add button to Lead form)
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define([‘N/ui/serverWidget’], (serverWidget) => {
const beforeLoad = (scriptContext) => {
if (scriptContext.type === scriptContext.UserEventType.VIEW) {
const form = scriptContext.form;
form.addButton({
id: ‘custpage_initiate_call’,
label: ‘Call Lead’,
functionName: ‘initiateCall’
});
form.clientScriptModulePath = ‘SuiteScripts/lead_call_client.js’;
}
};
return { beforeLoad };
});
Client Script (Triggered by button click)
/**
* @NApiVersion 2.1
* @NScriptType ClientScript
*/
define([‘N/currentRecord’, ‘N/https’], (currentRecord, https) => {
function initiateCall() {
try {
const rec = currentRecord.get();
const phone = rec.getValue({ fieldId: ‘phone’ });
const leadId = rec.id;
if (!phone) {
alert(‘No phone number found for this lead’);
return;
}
// Call Suitelet (backend)
https.post.promise({
url: ‘/app/site/hosting/scriptlet.nl?script=XXX&deploy=1’, // replace with Suitelet URL
body: JSON.stringify({
destination: phone,
eventID: ‘LEAD-‘ + leadId
}),
headers: {
‘Content-Type’: ‘application/json’
}
}).then(response => {
const resp = JSON.parse(response.body);
alert(‘Response: ‘ + resp.responseDescription);
}).catch(err => {
alert(‘Error: ‘ + err.message);
});
} catch (e) {
console.error(‘Error:’, e.message);
alert(‘Failed: ‘ + e.message);
}
}
return { initiateCall };
});
Suitelet (Server-Side API Call)
/**
* @NApiVersion 2.1
* @NScriptType Suitelet
*/
define([‘N/https’], (https) => {
function onRequest(context) {
if (scriptContext.request.method === ‘POST’) {
const body = JSON.parse(scriptContext.request.body);
// Prepare Voicebot API call
const response = https.post({
url: ‘https://backend.pbx.bonvoice.com/autoDialManagement/autoCallBridging/’,
headers: {
‘Content-Type’: ‘application/json’,
‘Authorization’: ‘Token {{Auth_Token}}’ // replace with your token
},
body: JSON.stringify({
autocallType: “5”,
destination: body.destination,
legACallerID: “4843518123”, // Example Caller ID
eventID: body.eventID,
voicebotProvider: “BONVOICE”, // replace
voicebotURL: “https://your-bot-url.com” // replace
})
});
scriptContext.response.write({
output: response.body
});
}
}
return { onRequest };
});
This is a sample integration that demonstrates how NetSuite can be extended to interact with external services like a Voicebot Auto Call Bridging API. By implementing this feature, you enable users to initiate automated calls directly from the Lead record with a single click, eliminating the need for manual dialing or switching between platforms. This will help you to accelerate lead engagement, reduce operational delays, and create a more seamless workflow for your sales team.