Bind NetSuite SuiteScript Client Side Code in Form View Mode

There are times when you need to run a client side script when a NetSuite internal form loads in view mode. ¬†It’s not obvious how to do this — there is no “on load” form event when the the form is loading for view mode. ¬†Hence, it isn’t easy to link and fire your custom NetSuite script when the form loads.

Here is what you need to do.  Create a dynamic inlinehtml field server side that will push a client side script into the HTML stream.  Use a UserEvent and call the script on the OnInit method.  See below for the sample code.

var html = '<SCRIPT language="JavaScript" type="text/javascript">';
html += "function bindEvent(element, type, handler) {if(element.addEventListener) {element.addEventListener(type, handler, false);} else {element.attachEvent('on'+type, handler);}} "; html += 'bindEvent(window, "load", function(){'; html += 'alert("window onload event fired - put our logic here");'; html += '});'; html += '</SCRIPT>';
// push a dynamic field into the environment
var field0 = form.addField('custpage_alertmode', 'inlinehtml', '',null,null); field0.setDefaultValue(html);

With this approach, you will be able to include your custom client side logic.   Many thanks to Sean, one of our senior developers, for producing a simple example here.  Do you see a different way to accomplish the same goal?

Be Sociable, Share!

Marty Zigman

Holding all three official certifications, Marty is Southern California's 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 25 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to setup a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - Google Plus - YouTube

| Tags: , , , , , | Category: NetSuite, Technical | 15 Comments


  1. Posted May 10, 2013 at 4:08 pm | Permalink

    Marty, you are a life saver.
    THIS little trick got me through!!

    What an AWESOME tip!

    I will be writing about this and referencing this page!


  2. Posted June 10, 2014 at 4:30 pm | Permalink

    This was very helpful, thanks Marty!

  3. Vijay Joshi
    Posted May 12, 2015 at 1:28 am | Permalink

    Is it possible to Deploy user event script to get all fields and values on suitelet deployed in Netsuite ERP, same a we do for records?

  4. Posted June 3, 2015 at 3:54 pm | Permalink

    Hi Vijay,

    I am not sure I understand what you suggesting. Can you state it a different way?


  5. Hitesh Kumar
    Posted July 2, 2016 at 1:10 am | Permalink

    I am getting the error form is not defined.
    I have created a script put your code in that and inserted in netsuit custom form.

  6. Posted July 4, 2016 at 5:50 pm | Permalink

    Hello Hitesh,

    Are you able to read any form data?


  7. kumar
    Posted July 18, 2017 at 5:42 am | Permalink

    Hi sir,

    I have a component item with group of items, and i need to show this items on advanced pdf, earlier in the item record ‘ DISPLAY COMPONENTS ON TRANSACTIONS’ checkbox not checked, now i chewcked this check box and i am gettin items on the print.
    Here my problem is the old sales orders which are created before i modified item record, those group of items are not coming on pdf print for old sales orders.

    Please help me on this sir. I should not edit the sales orders to resolve this issue.

  8. Posted August 3, 2017 at 12:44 pm | Permalink

    Hi Kumar,

    There is a good chance that the old Sales Orders need to be “Touched”. In our Prolecto Utilities Bundle, we have a Mass Update custom action that effectively allows you to edit and save a transaction without changing data. You may be able to do this also with a CSV upload.


  9. Gus Larson
    Posted March 8, 2018 at 1:38 pm | Permalink

    I was thinking I could use this trick to run a client script from the Order Requisitions page but there is no way to trigger a user event script from going to that page, as far as I know. Our users want to be able to override the item rate that is in the item record. I know you can do that once you get to the Order Requisitions page by changing Order Rate, but they want to do it initially when creating the Requisition by using the Estimated Amount, Estimated Rate fields and have that carry over to the PO. Is there a way to run a script on the Order Requisitions page?

  10. Posted March 10, 2018 at 10:46 am | Permalink

    Hi Gus,

    I haven’t done programming yet on the Purchase Order Requisition page. I have always assumed it was basically the purchase order record revealed in a limited user context. I suspect, at worst, I could get at it when it becomes a traditional purchase order.

    Finally, for a client with a paperless purchase order / vendor bill approval ambition, we built our own purchase requisition systemwith powerful transaction approval routing using SuiteLet’s here.


  11. Gus Larson
    Posted March 14, 2018 at 9:29 am | Permalink

    Nice! I used the advanced procurement workflows and made significant changes to them for our requisition approval process. I ended up just transforming the Requisition to a Purchase Order in the workflow upon final approval and just skipping the Order Requisitions page. Then the Item Rate doesn’t get changed back to what was on the Item record and that’s fine for us because we never put more than one Requisition on a PO. Now I’m having trouble because we are using Demand Planning and the Order Items feature goes right to making a PO. I need it to make a Requisition instead. Any ideas about that?

  12. Posted March 17, 2018 at 1:41 pm | Permalink

    Hi Gus,

    I don’t have specific recommendations as we haven’t seen this use case. But I suspect we could work through it. We tend to go to script to get full control. If you want to have one of our team members help, send me a note here.


3 Trackbacks

  1. […] Resources for helping me get through this particular task. One of his blog entry titled “Bind NetSuite SuiteScript Client Side Code in Form View Mode” gave me the answer to what I need to […]

  2. […] some basic understanding of development on the NetSuite platform. ¬†You may want to reference a previous article that offers more background about loading Javascript in NetSuite client side […]

  3. […] I had a request from a member of our logistics team to set the NetSuite Sales Order form to default to the logistics tracking tab when editing. I did some research and found some tips on other sites which led me to this solution. I found how to add an event listener to the NetSuite forms from Marty Zigman’s blog. […]

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>