<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- CSS File bootstrap.min.css - UPDATE THIS LINK ONCE UPLOADED TO NETSUITE-->
<link href="/core/media/media.nl?id=8761&c=TSTDRV2670723&h=T2hGKNOPEmYxfxGBHScCcbI30zXHNK32v9B2vBsM4WR-jJiC&_xt=.css" rel="stylesheet" />
<style type="text/css">
.hidden { display: none; }
.form-inline > * {
margin:0px 5px !important;
}
</style>
<title>Create Vendor</title>
</head>
<body>
<div id="defaultMenu" class="container" style="margin-top:10px;">
<div class="row align-items-center justify-content-center">
<div class="col">
<h4>Menu</h4>
<div class="btn-group-vertical">
<button id="createVendorMenuButton" type="button" class="btn btn-info btn-lg">Create Vendor</button>
</div>
</div>
</div>
</div>
<!--------------------------------------------------------------------------------------->
<!-- CREATE VENDOR SCREEN -->
<!--------------------------------------------------------------------------------------->
<div id="createVendorScreen" style="margin-top:10px;">
<div class="container">
<div class="row">
<div class="col-md-auto">
<div class="form-group form-inline">
<label for="vendorName">Vendor Name</label>
<input id="vendorName" type="text" value="" placeholder="Vendor Name" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-md-auto">
<button id="createVendorButton" type="button" class="btn btn-info btn-lg">Create Vendor Record</button>
</div>
</div>
</div>
</div>
<!-- jquery.3.2.1.min.js - UPDATE THIS LINK ONCE UPLOADED TO NETSUITE -->
<script src="/core/media/media.nl?id=8763&c=TSTDRV2670723&h=BVUHw_ThmPkbJRStRyxSHvfTTRH_ZQsa9NlJKkHOpRE4pbjm&_xt=.js" type="text/javascript"></script>
<!-- bootstrap.min.js - UPDATE THIS LINK ONCE UPLOADED TO NETSUITE-->
<script src="/core/media/media.nl?id=8762&c=TSTDRV2670723&h=3gEyhD-XUEG_DxY29qLZAHz6UmSEFUHu5vzMsjblGADNroFX&_xt=.js" type="text/javascript"></script>
<!-- WebApp_ClientScript.js - UPDATE THIS LINK ONCE UPLOADED TO NETSUITE-->
<script src="/core/media/media.nl?id=8758&c=TSTDRV2670723&h=Xii5wm_o6bZ54YYy503HpQQtjSwo26I0BN_efvHatvxgAYd-&_xt=.js" type="text/javascript"></script>
</body>
</html>
Step 3: Create a client script for the HTML page which will contact the Suitelet using AJAX.
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();
}
});
}
});
/**
*@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
}
});
Jaime Requena is a seasoned NetSuite Consultant and Solutions Architect, known for delivering WHITE GLOVE service to businesses. With 15+ years of experience and 3x certifications in ERP, Developer, and Admin, Jaime specializes in highly customized NetSuite accounts, transforming operations for 200+ satisfied customers all across the globe.
We aim to bring unmatched expertise and professionalism to your NetSuite initiatives. Let’s talk about how our NetSuite consultancy can make a difference!
It’s Been 4+ Years Now And We Have Worked With Hundreds Of Clients, Building Our Way To The Top, One Happy Client After Another! Their Voices Of Satisfaction Serve As A Testament To Our Success –