This article is relevant if you are seeking to change the default dropdown values that are selected when a NetSuite form is loaded and initialized.
Background
In a recent implementation of NetSuite’s Service Resource Planning (SRP), also known as “Advanced Projects”, our client sought to drive different user experiences depending on the role. The conventional wisdom is to produce different form definitions and bind these to the user role.
While the form modification technique usually does work, when you have many roles and forms, you may find that subsequent maintenance is challenging when logic needs to change. Furthermore, some changes on NetSuite forms are simply not able to be defined via the point-and-click customization framework.
Our case in point is the sublist views that drive the presentation of detail (lists) that hang off the header (main) form. These behaviors are governed a bit by role preferences — and they are also driven by behaviors to remember the user’s last login session. When these dropdown values change, NetSuite automatically refreshes the sublist view. How can we get control over this behavior?
Getting Control over the NetSuite Form Sublist View
Our client sought to dial in the specific sublist definition by role at all times. In our simple minds, we can use a script to modify the values on the page_init event. Yet, NetSuite offers no library to modify the values in the dropdown to achieve the objective.
Activate JQuery to Modify the Document Object Model (DOM)
In cases where no NetSuite API is provided, it makes sense to responsibly work outside the NetSuite library to produce the result. NetSuite provides undocumented access to the JQuery library. Accessible via a global object “NS”, we can access JQuery via “NS.JQuery”
When working directly with the Document Object Model, the trick is to use the browser’s inspection tools to help you look around and learn about the structure of the page. Review the images to get a feel for the experience. Once you identify the ID of the dropdown in question, you can activate this JQuery commands to achieve your objective:
//Assumes within client-side script in the desired event function. //Note, NetSuite adds numerical suffixes that change from time to time //and thus your query may be optimized to be generalized. Below, we //show the suffix to connect the concept. NS.jQuery('[id^="searchid1"]').val('Planned Project Costs').change(); NS.jQuery('[id^="hddn_searchid1"]').val(1241).change();
Notice that there are two elements here to modify. One is the dropdown of the visual element. The other is a hidden field that requires a specific ID. These IDs can be discovered in your browser inspection work. In the example, the values are being changed while the change event is being raised to drive the sublist refresh action.
When Working Outside the NetSuite Documented API
Although JQuery is available to modify NetSuite user interface web pages, you can use standard JavaScript browser functions — however, the web development community likes to use JQuery because it provides a compatibility layer between different browsers and the syntax is more intuitive.
Finally, to be responsible for modifying NetSuite in this manner means that NetSuite may make modifications to its user interface and our scripting efforts may thus fail. Thus, there is an inherently higher risk doing this and naturally, NetSuite is off the hook offering support when you choose this course of action. Nevertheless, you are not stuck and can achieve your objective.
Work with Respected NetSuite Professionals
I would like to thank two members of the Prolecto team who contributed to this article. I watched both Carl Z. and Boban B. who offered thinking to each other to help solve the client challenge — their dialogue inspired me to share this with you. Our team collaborates together to solve the most challenging NetSuite endeavors.
If you found this article helpful, feel free to be notified when new articles are published. If you are a NetSuite technologist, hold high standards for care, seek autonomy and be affiliated with other like-minded professionals, let’s have a conversation.