Steps to Show an Alert on a Sales Order with JQUERY

  1. Include Necessary Files:
  • jquery.min.js
  • jquery.alert.js
  • jquery.alert.css
  1. You can host these files in your NetSuite account (File Cabinet) or use any CDN to refer.
  2. Create a Client Script:
  • This script will be called in the Page Init function 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);
}
  1. Deploy the Client Script:
  • Deploy the script for the Sales Order record.
  1. Create a Function to Show Alert:
  • This function will be called in the validateLine event 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.

Leave a comment

Your email address will not be published. Required fields are marked *