Marty Zigman - The NetSuite Expert

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

Prolecto Labs Accelerator Templates

How To: Automate NetSuite Repetitive Operations

Accounting NetSuite Technical

Tags: , , , , , , , ,

This article is relevant if you are a NetSuite power user and you want to change default field information on vendor bill or other transactional entities, such as an invoice, sales order, purchase order, etc.

Standard Business Operations Promote Automation Opportunities

Most every business has recurring patterns in their transactional operations.  In our NetSuite Systems Integrator practice, we work with both employees and contractors.  Our work is driven heavily by the weekly timesheet.  Hence, we have shaped our business operation and our performance measurements to be driven in a weekly orientation.  (As a consequence of this perspective, but  not part of the scope of this discussion, we elected to use a 4-4-5 accounting period.  Read about it here).

Because our inventory is human capacity, we purchase professional help like wholesale companies purchase goods.  The weekly timesheet  is based on a Sunday to Saturday work week and it is the anchoring document we use to account for all of our action.    We use NetSuite Purchase Orders to buy contractor services.  A contractor timesheet is due on Monday morning and accounts for last week’s work.  That timesheet is treated like a Purchase Order Inventory Receipt which becomes the basis of a NetSuite Vendor Bill.

Changing Default Behaviors on NetSuite Transaction Form Loads


When creating a new Vendor Bill, NetSuite defaults the date to today.  The reference number is blank.   In our case, we want the date to always land on last Saturday as it lines up with the last day of the timesheet and appropriately links to our 4-4-5 accounting period orientation.  Also, because our contractor timesheets are effectively demands for payment but they do not have traditional vendor invoice numbers, we want to create a standard for the reference number as “Timesheet YYYYMMDD” where “YYYY” is year, “MM” is month, and “DD” is day.

This is a perfect opportunity to change NetSuite’s default behavior using a relatively simple Client SuiteScript.   The script below is beginner level and can be used as a template to help you build your own NetSuite form load logic.

Sample NetSuite Client SuiteScript to Change Form Load Behaviors

For brevity, I will assume that the basic way you install scripts is understood (and well documented in NetSuite’s Help).  The following  JavaScript is setup as a NetSuite Client script. The script deployment record applies to the Vendor Bill and links the “Page Init” call to our custom function hook point called “id001_pri_VendorBillSetDefaults”.

//-----------------------------------------------------------------
//Function:		id001_pri_VendorBillSetDefaults
//Record: 		Vendor Bill
//Script Type: 		Client
//Description:  	Set the date on the vendor bill to be last
//			Saturday and set the Bill reference name
//			to "Timesheet YYYMMDD"
//Date:			MZ 20130122
//------------------------------------------------------------------
function id001_pri_VendorBillSetDefaults(type){
	var func = 'id001_pri_VendorBillSetDefaults ';
	nlapiLogExecution('DEBUG', func + 'with type:', type);

	//alert('calling client script with type: ' + type);

	if (type == 'create' || type == 'copy') {
		var sat = getLastSaturday();
		//alert('Last Saturday is: ' + getLastSaturday());
		nlapiSetFieldValue('trandate', nlapiDateToString(sat));
		//alert('Timesheet ' + sat.getFullYear() + ('0'+(sat.getMonth()+1)).slice(-2) + ('0'+sat.getDate()).slice(-2));
		nlapiSetFieldValue('tranid', 'Timesheet ' + sat.getFullYear() + ('0'+(sat.getMonth()+1)).slice(-2) + ('0'+sat.getDate()).slice(-2));

	}
}

function getLastSaturday() {
	var today = new Date();
	var lastweek = nlapiAddDays(today, - 7);
	var saturday = nlapiAddDays(lastweek, 6 - lastweek.getDay())
	return saturday;
}

Summary

NetSuite is a powerful platform for running your business.  With your capacity to innovate, it can drive down your operating cost and improve the value of the work you perform.

If you are seeking to automate your business operation with NetSuite and would like some help, contact us for a conversation.

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - YouTube

About Marty Zigman

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

Biography • Website • X (Twitter) • Facebook • LinkedIn • YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *