Step 4: Create the Suitelet.
Code for WebApp_CreateVendor_SL.js:
Jaime Requena
–
November 7, 2022
I have created many custom applications using HTML, CSS, JQuery, and Bootstrap. A backend Suitelet is used to communicate with NetSuite. I will detail a basic web application which uses these technologies to create a vendor record in NetSuite.
Download Bootstrap:
https://getbootstrap.com
Download JQuery:
https://jquery.com
Code for WebApplication.html
Create Vendor
Menu
Code for WebApp_ClientScript.js:
/*
* Name: WebApp_ClientScript.js
*/
var suitelet = ''; // PUT EXTERNAL LINK TO SUIELET HERE
$(document).ready(function(){
hideScreens();
$('#defaultMenu').show();
// Show the menu
$('#createVendorMenuButton').click(function(){
hideScreens();
// show create vendor screen
$('#createVendorScreen').show();
$(document).prop('title', 'Create Vendor');
$('#vendorName').focus();
});
$('#createVendorButton').click(function(){
var vendorName = $( "#vendorName" ).val();
if (!vendorName) {
alert('Vendor Name is required.');
}
else {
vendorName = vendorName.trim();
createVendor(vendorName);
}
});
function hideScreens() {
$('#defaultMenu').hide();
$('#createVendorScreen').hide();
}
function createVendor(name){
$.ajax({
url: suitelet+'&rf=createVendor&cb=_createvendor',
dataType: 'jsonp',
jsonpCallback:'_createvendor',
type:'post',
data:{
name : name
}
})
.done(function(data){
console.log('data', data);
if (data.error) {
alert('Error : ' + data.error);
}
else {
alert('Vendor ' + name + ' created successfully. Internal ID is ' + data.recordId);
hideScreens();
$('#defaultMenu').show();
}
});
}
});
Code for WebApp_CreateVendor_SL.js:
/**
*@NApiVersion 2.1
*@NScriptType Suitelet
*/
/* Name : WebApp_CreateVendor_SL.js
*
* Back end suitelet used to create vendor record.
*/
define([ 'N/record'], (record) => {
onRequest = (context) => {
log.debug('rf', context.request.parameters.rf);
const routingFunction = context.request.parameters.rf;
const callback = context.request.parameters.cb || '';
try {
switch(routingFunction){
case 'createVendor':
data = createVendor(context);
break;
}
data = callback + '(' + JSON.stringify(data) + ')';
log.debug('data sending', data);
}
catch(e) {
data = { error: 'Failed : ' + e.message };
data = callback + '(' + JSON.stringify(data) + ')';
log.debug('Error', JSON.stringify(e));
}
context.response.setHeader('Custom-Header-Content-Type', 'application/json');
context.response.write(data);
}
createVendor = (context) => {
const vendorRecord = record.create({
type: 'vendor',
isDynamic: true
});
vendorRecord.setValue('companyname', context.request.parameters.name);
vendorRecord.setValue('subsidiary', 1); // default the subsidiary
const recordId = vendorRecord.save();
return {
recordId : recordId
};
}
return {
onRequest: onRequest
}
});

Step 7: Open the Web Application HTML page in your browser and create your new Vendor.The first page is simply a menu with button which when clicked takes you to another page to enter the vendor’s name. When creating a small application, I like to put all the HTML in one page separated by DIVs.
Landing Page:

Page where you enter a Vendor Name:

After successful creation of the vendor record you get an alert and are then taken back to the menu page.

Although this is a very simple application, it shows the power of being able to work outside the confines of a front end Suitelet. You have complete control over how the user interface looks and behaves using the many libraries available for free.
Do you need help building a custom application for NetSuite? Please Contact Suite Tooth Consulting here to set up a free consultation.
If you liked this article, please sign up for my newsletter to get these delivered to your inbox here.
Do not hesitate to contact us. We’re a team of experts ready to talk to you.