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.
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?
I changed filters to null in
var s = nlapiSearchRecord(‘invoice’, null, filters, columns);
and it now works
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
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…
Paul,
Consider this article. We are in the same domain so it should work:
https://stackoverflow.com/questions/10748449/access-and-change-parent-page-from-iframe-with-jquery
Marty