- Include Necessary Files:
jquery.min.jsjquery.alert.jsjquery.alert.css
- You can host these files in your NetSuite account (File Cabinet) or use any CDN to refer.
- Create a Client Script:
- This script will be called in the
Page Initfunction to add the necessary files to the HTML DOM of the NetSuite pages.
function OnPageInit() {
AddJavascript('http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js', 'head');
setTimeout(function() {
AddJavascript('https://system.netsuite.com/core/media/media.nl?id=253&c=TSTDRV896291&h=c3fc87f394f396552e09&_xt=.js', 'body');
}, 3000);
AddStyle('https://system.netsuite.com/core/media/media.nl?id=254&c=TSTDRV896291&h=50d488b82c3c3ed7263c&_xt=.css', 'head');
}
function AddJavascript(jsname, pos) {
var tag = document.getElementsByTagName(pos)[0];
var addScript = document.createElement('script');
addScript.setAttribute('type', 'text/javascript');
addScript.setAttribute('src', jsname);
tag.appendChild(addScript);
}
function AddStyle(cssLink, pos) {
var tag = document.getElementsByTagName(pos)[0];
var addLink = document.createElement('link');
addLink.setAttribute('type', 'text/css');
addLink.setAttribute('rel', 'stylesheet');
addLink.setAttribute('href', cssLink);
tag.appendChild(addLink);
}
- Deploy the Client Script:
- Deploy the script for the Sales Order record.
- Create a Function to Show Alert:
- This function will be called in the
validateLineevent of the Sales Order screen.
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(['N/record', 'N/ui/message'], function(record, message) {
function validateLine(context) {
var currentRecord = context.currentRecord;
var sublistName = context.sublistId;
if (sublistName === 'item') {
var itemId = currentRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'item'
});
if (itemId === 123) {
jAlert('Item Alert', 'Item with internal ID 123 has been added to the sales order.');
return true;
}
}
return true;
}
return {
validateLine: validateLine,
pageInit: OnPageInit
};
});
In this script:
- OnPageInit: Adds the necessary jQuery and jAlert files to the DOM.
- validateLine: Checks if an item with internal ID 123 is added to the sales order and shows an alert using
jAlert.
Deploy this script to the Sales Order form, and it will show an alert when the specified item is added.