Some APIs & methods(of Netsuite) and its use in Netsuite Suite Script
There are some APIs and Methods in Netsuite Suite Script that we all Netsuite Developer may know , but we may not know where they can be used and where they can’t .
Here are some APIs and methods with their usability which can help you while scripting in Netsuite.
nlapiInsertSelectOption(fldnam, value, text, selected):
Adds a select option to a select or multiselect field(remember: which is added via script). This API can only be used on select or multiselect fields that are added via the SuiteScript UI Objects API (for example “Suitelets” or “beforeLoad User Events”).
That means you can’t use this to add options to any standard dropdown in any record.
But if you have created a dropdown through script , then you can use this to add a new element to dropdown.
Ex.
User Event Before Load Event :
function SalaorderBeforeLoad(type, form) {
var select = form.addField(‘custpage_mfsdrp’, ‘select’, ‘Customer Address’, null, ‘main’);
}
Here the select field is created in UserEvent Before Load event.
Client Field Change Event :
function CustomerFieldChange(type, name) {
nlapiInsertSelectOption(‘custpage_mfsdrp’, addrId, addr);
}
nlobjField:
If you use nlapiGetField(fieldname) in a client script to return a nlobjField object, the object returned is read-only(get the properties of that field). This means that you can use nlobjField getter methods (like getType(), getLabel())on the object to get its type,label etc, . But you cannot use nlobjField setter methods(like setType(), setLabel(),addSelectOption()) to set field properties.
Ex:
var shipField = nlapiGetField(‘shipaddresslist’);
alert(shipField.getType()); //getting the Type(NO ERROR)
alert(shipField.getLabel()); //getting the Label(NO ERROR)
shipField.addSelectOption(addIdDrp, labeldrp, true); //ERROR
If you will write this to add the a new address to “Ship To Select” dropdown , it will not work.
getSelectOptions(filter, filteroperator) :
This API is used to obtain a list of available options on a select field( applied to both standard and custom select fields). Only the first 1,000 available options will be returned by this API.
Example
This sample creates a Sales Order record and then set the Customer (entity) field to a specific customer . Then corresponding addresses of the customer will be available to Ship To Select select option .
var record = nlapiCreateRecord(‘salesorder’); //Create salesorder record.setFieldValue(‘entity’, ’13’);//set customer var field = record.getField(‘shipaddresslist’);//get the Ship To Select field
var options = field.getSelectOptions(); //all the options of the Ship To select Dropdown are now available
NOTE: please refer to Netsuite Help Guide to know more about it
Redirecting to a new Page From Client Script:
When you want to go to another page, Try this:
var linkURL = “given URL”;
window.open(linkURL, “netsuite”, “menubar=1,resizable=1,width=900,height=400”);
return true;
Ex 1:To go to another page:
var linkURL = “https://system.netsuite.com/app/common/entity/address.nl?etype=custjob&ship=T&target=address:shipaddresslist&label= Ship+To+Select&entity_id= ” + customerID + “&target2=address:billaddresslist&entity=” + customerID;
window.open(linkURL, “netsuite”, “menubar=1,resizable=1,width=900,height=400″);
return true;
Note :Only tested for Netsuite Pages
Ex 2:To run another SUITELET:
var linkURL = nlapiResolveURL(‘SUITELET’, ‘customscript_address_suitelet_script’, ‘customdeploy_address_suitelet_script’, null);
window.open(linkURL,”netsuite”, “menubar=1,resizable=1,width=900,height=400”);
return true;