Marty Zigman Marty Zigman
Prolecto Labs Accelerator Templates

NetSuite Portlet Code Example: Get Last Invoice Number

NetSuite Technical

Tags: , , , ,

This article is relevant if you want to learn how to use SuiteScript to produce NetSuite Portlet HTML.

Background


In a recent exercise to help a client learn how to produce SuiteScript to draw HTML in a Portlet, we pulled the last invoice number used into view as a learning example.  This was handy for the client as they frequently needed to know the invoice number for other practices in their business operation.  I decided to bring it into our own NetSuite operation to help illustrate how you can do the same.

SuiteScript Code Example

Here is the basic SuiteScript code to get the last invoice number:

function getLastInvoiceNumber(portlet, column){
	portlet.setTitle('Last Invoice Number');

	var columns = new Array();
	columns[0] = new nlobjSearchColumn('internalid', null, 'max');

	var s = nlapiSearchRecord('invoice', null, null, columns);
	var content = 'Invoice #: ';
	if (s){
		var id = s[0].getValue(columns[0]);
		if (id){
			var tranid = nlapiLookupField('invoice', id, 'tranid');
			content += tranid;
		};
	};
    portlet.setHtml( content );
};

The code example is nice because it shows off how to use an aggregate function (max).  It also is simple to understand because we are doing so few things.

Setup Script and Script Deployment

Save the code in a file and upload it to your SuiteScripts file cabinet.  Then, create a new Script defintion of type Portlet.  See image below for the script definition.

 

Here is the script deployment information.   Be sure to set the audience correctly so that they have permssions to run the script.  Note, the audience should also have at least read permissions on the Invoice record.

Portlet Definition

Click on any Tab to draw a dashboard.  Click the ‘Personalize Dashboard’ link on the upper right hand side of page and  Drag a ‘Custom Portlet’ to the dashboard.  Then, click the upper right icon to Setup the content to draw in the portlet.  See image for example.  You should get content to draw if your permissions are setup right and there are no issues in the code. 

Get More out of NetSuite

My team and I love to innovate on the NetSuite platform.  If you want to get more out of your NetSuite investment, contact us.

 

 

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

5 thoughts on “NetSuite Portlet Code Example: Get Last Invoice Number

  1. Pete Reid says:

    Thanks for the example but I’m getting an Unexpected_Error with details;

    ReferenceError: “filters” is not defined. (show_company_id.js$35190#7)

    I don’t suppose you’d have any idea on what I might have done wrong?

  2. Pete Reid says:

    I changed filters to null in

    var s = nlapiSearchRecord(‘invoice’, null, filters, columns);

    and it now works

  3. Marty Zigman says:

    Thank you Pete! When I orginally posted the code, I tweaked it a bit because we had a reference to an empty Filters array. I updated the code snippet now due to your findings.

    Marty

  4. Paul says:

    Is there any way to use these Portlet scripts to execute a jQuery command on a NetSuite page?
    I want to use jQuery to hide specific element(s) on the page…

Leave a Reply

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