SUITESCRIPT 2.0 EXAMPLES


81
Here I will be posting the most used scripts from Suitescript 2.0. These code examples are meant for beginners to be a quick start so they can quickly get a script started and add their code to them. I tried to keep them short. If you are a beginner I recommend you to check Netsuite’s Help section and navigate to Suitescript 2.0 API so you can learn more about each.

Client Script

Note: Check out how the helper functions in clientscript have to be nested inside the main runClientscript function. This is something particular to client scripts.
var SEARCHMODULE;
/**
*@NApiVersion 2.x
*@NModuleScope Public
*@NScriptType ClientScript
*/
define([‘N/search’], runClientscript);
      
function runClientscript(search){
    SEARCHMODULE = search;
  
    //*********** HELPER FUNCTIONS ***********
    function lineInit(context) {
//SEARCHMODULE.load(123);
context.currentRecord;
context.sublistId;
alert(“lineInit Triggered!”);
        return;
}
    function pageInit(context) {
context.currentRecord;
context.mode;
alert(“pageInit Triggered!”);
        return;
}
    function postSourcing(context) {
context.currentRecord;
context.sublistId;
context.fieldId;
alert(“postSourcing Triggered!”);
        return;
    }
    function saveRecord(context) {
context.currentRecord;
alert(“saveRecord Triggered!”);
        return true; //Return true if you want to continue saving the record.
    }
    function sublistChanged(context) {
context.currentRecord;
context.sublistId;
alert(“sublistChanged Triggered!”);
    }
    function validateDelete(context) {
context.currentRecord;
context.sublistId;
alert(“validateDelete Triggered!”);
return true; //Return true if the line deletion is valid.
    }
    function validateField(context) {
context.currentRecord;
context.sublistId;
context.fieldId;
context.line;
context.column;
alert(“validateField Triggered!”);
return true; //Return true to continue with the change.
    }
    function validateInsert(context) {
context.currentRecord;
context.sublistId;
alert(“validateInsert Triggered!”);
return true; //Return true if the line insertion is valid.
    }
    function validateLine(context) {
context.currentRecord;
context.sublistId;
alert(“validateLine Triggered!”);
return true; //Return true if the line is valid.
    }
    
    function fieldChanged(context) {
context.currentRecord;
context.sublistId;
context.fieldId;
context.line;
context.column;
alert(“fieldChanged Triggered!”);
        return;
    }
    
    var returnObj = {};
    returnObj.lineInit = lineInit;
returnObj.pageInit = pageInit;
returnObj.postSourcing = postSourcing;
returnObj.saveRecord = saveRecord;
returnObj.sublistChanged = sublistChanged;
returnObj.validateDelete = validateDelete;
returnObj.validateField = validateField;
returnObj.validateInsert = validateInsert;
returnObj.validateLine = validateLine;
    returnObj.fieldChanged = fieldChanged;
    return returnObj;
}

User Event Script

Suitelet


admin

0 Comments

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