Suitescript 2.0 Quickstart Examples
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
var SEARCHMODULE; /** *@NApiVersion 2.x *@NModuleScope Public *@NScriptType UserEventScript */ define(['N/search'], runUserEvent); function runUserEvent(search) { SEARCHMODULE = search; var returnObj = {}; returnObj.beforeLoad = beforeLoad; returnObj.afterSubmit = afterSubmit; returnObj.beforeSubmit = beforeSubmit; return returnObj; } function beforeLoad(context) { //SEARCHMODULE.load(123); log.debug('beforeLoad Triggered'); context.newRecord; context.type; context.form; return; } function afterSubmit(context) { //SEARCHMODULE.load(123); log.debug('afterSubmit Triggered'); context.newRecord; context.oldRecord; context.type; return; } function beforeSubmit(context) { //SEARCHMODULE.load(123); log.debug('beforeSubmit Triggered'); context.newRecord; context.oldRecord; context.type; return; } |
Scheduled Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
var SEARCHMODULE; /** *@NApiVersion 2.x *@NScriptType ScheduledScript *@NModuleScope Public */ define(["N/search"], runScheduledScript); //********************** MAIN FUNCTION ********************** function runScheduledScript(search){ SEARCHMODULE = search; var returnObj = {}; returnObj.execute = execute; return returnObj; } function execute(context){ //SEARCHMODULE.load(123); context.type; log.debug("ScheduledScript Triggered"); } |
…