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 | 11 Comments

8 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!

    Thanks!

  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?

    Marty

  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?

    Marty

  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.

    Marty

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>