ALERT IN NETSUITE USING USER EVENT BEFORE LOAD SCRIPT

HOW TO THROW ALERT FROM USER EVENT BEFORE LOAD SCRIPT?



It is a well known fact that alert can be thrown from client script by directly using alert() method. But lot of times developer needs to use user event script as client script has several limitations like not being able to run as admin. It always runs the script using the logged in user's role. Client script also doesn't get triggered when you view a record. It gets triggered only on edit, create and copy.

Alert can be thrown from user event script by using a mix of  html code with Netsuite API. So, first you will to create a custom field of type inline html. Label is not required for this field. This field can be created using form object in the before load function.

Then we can set an html alert in that field as default value. The code snippet is given below


function UE_BeforeLoad(type, form, request)

{


            var alert_value = "<html><body><script type='text/javascript'>window.alert('HELLO..UE ALERT')</script></body></html>";
    
            var field = form.addField('custpage_alertfield' ,  'inlinehtml');
    
    
            field.setDefaultValue(alert_value);
    
     
}



NETSUITE ACADEMY

Comments

  1. Thank you for posting this! My first delve into SuiteScript was starting to get me down when I couldn't even create a javascript window alert. Made some modifications and got it working for my needs.

    Also, if anyone wants to add line breaks in these alerts, I'll save you from reading a whole stack overflow argument thread. Use \\n to make a new line.

    ReplyDelete
  2. Hi I am new to suite script. Can you post the full code for this ? thank you

    ReplyDelete
  3. Great stuff. I enjoyed trying this out. Wish I had a team of netsuite passionate enthusist to provide answers like these to every questions I get!

    ReplyDelete

Post a Comment

Popular posts from this blog

HOW TO CREATE SUITELET ASSISTANT IN NETSUITE?

HOW TO CREATE A FUNCTIONALITY TO PRINT GL IMPACT OF A TRANSACTION IN NETSUITE?