We are working as quickly as possible to fill out the server SuiteScript documentation and include examples. I thought I would include an example I developed this evening to handle a customer request, which was to include the primary contact's fax # on the sales order. Hopefully taking a look at this will give you scripters a hint of the power you will have available with SuiteScript.
Note for the example below to work you must create a transaction body field on sales transactions with id = "contactfax" and store value unchecked. Because of an issue fix, the example will work in the version of NS coming out next Monday, June 5.
To use this script, create a new user event server script from setup > customization (you must have the Server SuiteScript feature turned on), give the script a name, upload this file as the script file, fill out "beforeLoadRecord" as the Before Load function, and under deployments add "Sales Order". That's it! Every time you view or edit a sales order this script will run and put the primary contact's fax # into the custom field.
// This script sets a custom field on sales orders to the fax # of the customer's primary contact
function beforeLoadRecord(type)
{
// only run this script for existing records
if (type.toLowerCase() == 'create')
return;
// Get the current record
var record = nlapiGetNewRecord();
// Get the entity (customer) for this order
var customer = record.getFieldValue("entity");
// Execute a search to retrieve the primary contact's fax
// Filter to id = the customer of the sales order gleaned above
var filters = new Array();
filters[0] = new nlobjSearchFilter("internalid",null,"anyof",customer);
// Return the fax # from the primary contact joined search
var results = new Array();
results[0] = new nlobjSearchColumn("fax","contactprimary");
// Execute the search
var searchresults = nlapiSearchRecord( 'customer', null, filters, results );
// Retrieve the result field
var contactfax = searchresults[0].getValue("fax","contactprimary");
// Set it into the record
record.setFieldValue('custbodycontactfax',contactfax);
}
(Note two errant spaces in the code above, "custom er" and "contactf ax". No idea how to get rid of them from the post)