Thursday, July 31, 2008

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 ofsetAdjustmentAcct”.


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:

Tuesday, July 29, 2008

My first Java Program, My First Blog

In this tutorial we assume that you have JAVA installed on your computer and have set the necessary environmental variables in order to compile your programs. If you need more information on this please visit Java.com or http://www.jibble.org/settingupjava.php to install the proper developer’s kit for your operating system.


With every programming language comes the much dreaded starting point in which the developer will have to come to terms with the inevitable "hello world program". In this brief example I will break this cliche a bit and show you how to do a "Hello, Google!" program. No this will not increase your search engine rankings or make you part of an elite developer's pack, but it will start you off with the basic fundamentals of the Java Programing language, and show you how to output a string to the console/terminal window of your operation system. 


To begin we start with the basic code: 


public class HelloGoogleCode {

public static void main (String[] args){

System.out.print("Hello, Google!");

}

} 


The First Line:

Notice we start the program with the words "public" and "class" and follow that with a descriptive term to label our class “HelloGoogleCode”.  The words public and class are considered to be Java Keywords (we will get into this in more depth later) . 

In addition you will notice the first letter of the class name is UpperCase as well as the following words “Google” and Code”. This is a common naming convention in the Java programming language and will determine what you will name your file as. In this instance we would save the java file as “HelloGoogleCode.java”. It should also be noted that it is customary to label your class names as nouns. 


The Second Line

In the second line of code  we use the main method syntax .In the Java programming language this is read by the Java Virtual Machine (JVM) as the starting point to the program’s execution, and it is here where the main method is called (and any other methods you may have).



The Third Line

Finally in the third line this is where we output the text string “Hello, Google” to the console, using the “System.out” object and the “print” method. It is important to note the line System.out.print("Hello, Google!"); is considered to be a statement and must be followed by a semicolon. 


Compile it!

To compile the above code in the windows environment, I would generally use a program like notepad++ (free) to write and save the code. Then open up the command line utility in windows, navigate to the directory when the file has been saved by using the change directory command i.e. 


cd Desktop


javac HelloGoogleCode.Java


java  HelloGoogleCode


The output, if compiled with no errors, should be:


Hello, Google!


Please note that this method will only work if you have Java installed on your machine and have properly set up the environmental variables on your system. 



As you can see there is a lot going on in these couple lines of code, I will expand upon the basic fundamentals of JAVA and other  OOP (Object Oriented Programming) principles in later tutorials. But for now I will leave you will this minor titbit and hope to bring you more tutorials very soon. 

Labels: