Netsuite: speedline your data entry with the SuiteScript API
If you are like most IT professionals you often times find yourself trying to automate your processes to save time. When working in Netsuite I found that using the SuiteScript API, and a little bit of JavaScript can be a real time saver.
In this example I will show you how to use a basic method call to pre-fill your “adjust inventory form”. This method can be used on pretty much any form that you can attach a script to in Netsuite e.g. customer records, inventory, etc.
To begin we create a basic function in a text editor of your choice, Since I am using a Macbook Pro, I will be using TextWrangler because it works great, loads fast and most importantly it is free!.
Our first function will serve as a calling point- if you will- to execute the following set of small functions that we will create in order to “pre-fill” the following Netsuite fields.
- Adjustment Account
- Department
- Class
- Memo
- Adjustment Location (in case you have more that one)
function callAll(){
setAdjustmentAcct();
setDepartment();
setClass();
setMemo();
setAdjLoc();
}
Next we will create our second function as follows.
function setAdjustmentAcct(){
if (nlapiGetFieldValue('account').length == 0 ){
nlapiSetFieldValue('account', 69, null, true);
}
In line 1 we create the basic syntax for a JavaScript function and and give it the descriptive name of “setAdjustmentAcct”.
In line 2 (ignoring the white space) we create a conditional statement to see if the adjustment account field has a value. We do this by using the "nlapiGetFieldValue()"method of the SuiteScript API by passing the field id name account to the argument. (if you are having trouble finding the field id names, simply click on the field label and check the lower right corner screen shot 1).
In line 3 we use the "nlapiSetFieldValue()"method to set the “adjustment account['s]” field value to the corresponding general ledger account Id. In this case, it will be set to one of the "cost of goods sold" inventory accounts, which has a field id of 69. The next argument is set to "null" and the following to true. Since this is a statement we want to end it by using a semicolon.
Line 4 closes out the function with a curly brace “}”.
Repeat this pattern for the remaining functions as follows:
function setLocation(){
if (nlapiGetFieldValue('adjlocation').length == 0){
nlapiSetFieldValue('adjlocation', 1, null, true);
}
}
function setClass(){
if (nlapiGetFieldValue('class').length == 0){
nlapiSetFieldValue('class', 10, null, true);
}
}
function setDepartment(){
if (nlapiGetFieldValue('department').length == 0){
nlapiSetFieldValue('department', 10, null, true);
}
}
function setMemo(){
if (nlapiGetFieldValue('Memo').length == 0){
nlapiSetFieldValue('Memo', 'This is my Memo', null, true);
}
}
Save the file with a name such as “setInventoryAdjs.js”- or something similar -so that you will remember what it is when you upload it to your suitescript folder in netsuite.
Download the complete script here: setInventoryAdjs.js
Coming Soon!, "How to" attach a SuiteScript to a form.
Labels: netsuite


