Adding Client Scripts on “View” of Record
Is there something you would like to change on page record to be displayed differently, but don’t want to re-write the entire record page into a Suitelet?
Do you want to customize a record to provide for a better user experience? It can be done with a few easy steps. Follow this guide to get around gaps in NetSuite’s features and make NetSuite work more efficiently for your business processes.
Client scripts can be used for a multitude of different features, but what if you want a client script to execute on the “view” of record?
Why execute a client script when viewing a record?
The quick answer is to add features not officially supported by NetSuite. Code from client scripts is injected directly into the page. With some creativity, this allows for some nice UI improvements such as highlighting lines in child records, redirecting to another page, or better loading modals.
Adding the script
Unfortunately, the standard method of deploying a client script via the NetSuite interface will not work for “view” types. Instead, a user event script’s form argument is used to manually attach the client script.
1. Create a new client script record like normal, but do not create any deployments.
2. Create a user event script following the example below.
Replace customscript_my_script_id with the actual ID of the client script created in the first step.
3. Create a user event record in NetSuite following the usual procedure.
4. Deploy the UE script to any record types that you want the corresponding client script to be on.
That’s it! The client script will now be included when viewing the selected records.
There are a few limitations.
The usual nlapiGetFieldValue and similar functions are unavailable. Instead, you will need to either load the record or use nlapiLookupField in conjunction with nlapiGetRecordId.
Another problem, the usual call to the defined page init function will not fire. Instead, include the standard jQuery on ready function in your client script file.
Written by: Eddie Atter, Senior Technology Consultant
Need help with NetSuite?
Want to talk to an expert before you spend a couple of days or weeks on an issue? Protelo is here to help. From simple questions to more complex questions, we have a dedicated team of highly experienced business consultants ready to help!