ANS-1473 · SUITESCRIPT DEVELOPMENT
How to Create a Button to Redirect Users to the NetSuite Home Page?
Leverage SuiteScript 2.x to add a custom button to a NetSuite form that navigates users directly to the home dashboard.
Short answer
To redirect to the NetSuite Home Page from a custom button, use the N/url module's url.resolveTaskLink function to get the home page URL. Assign this URL to window.location.href within a client script function, which is then triggered by a form button. Ensure the client script is properly linked to the form.
Scenario
Users often require quick navigation back to the NetSuite Home Page from various custom forms or records. Implementing a dedicated button provides an efficient way to enhance user experience and streamline navigation within the NetSuite environment.
Solution
To implement a button that redirects users to the NetSuite Home Page, follow these steps:
Create a Client Script:
Develop a client script that utilizes the
N/urlmodule to resolve the home page's task link and then redirects the browser.
javascript//..........Client Scriptfunction homeButton() {var homeUrl = url.resolveTaskLink({id: 'CARD_-29' // This is a common ID for the home page in NetSuite; specific IDs may vary.});window.location.href = homeUrl;}Add a Button to the Form:
In your SuiteScript User Event (SSU) script or form customization, add a button that calls the client script function. Ensure the client script is properly linked to the form.
javascript//..........User Event Script (or similar form customization)var homeButton = form.addButton({id: 'custpage_homebutton',label: 'Home',functionName: 'homeButton'});Note: The functionName parameter should refer to the function name without parentheses. The client script containing this function must be explicitly linked to the form using form.clientScriptModulePath or form.clientScriptFileId for the button to function correctly.The task ID, such as 'CARD_-29', can often be identified by accessing the page source in your browser's developer tools and searching for 'taskId' or similar identifiers within the HTML.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
