Friday, October 5, 2018

Dynamically Add a Button in User Event Scripts

Image
Duration: 5 minutes


Important Note:
This is only an example; please change the name, title, id and deployment of the scripts based on business requirement

Script Deployment and Installation:

Navigate to Setup > Customization > Scripting > Scripts > New > User Event
     > Name = Add Button
     > ID = customscript_add_button
     > Script File = <Javascript file uploaded>
     > Before Load Function = beforeLoad_addButton
     Click Save & Deploy
     
   On the deployment page
     > Title = Add Button Deployment
     > ID = customdeploy_add_button
     > Applies To = Employee
     > Execute as Admin = checked
     > Roles = check select all
     Click Save


function beforeLoad_addButton(type, form) {
   // The second parameter of the event it will return the current form of the record
   form.setScript('customscript_add_button'); // sets the script on the client side
   form.addButton('custpage_buttonalert', 'Alert', 'onclick_callAlert()'); 
   // addButton(name, label, script)
   
   // name - The internal ID name of the button. The internal ID must be in lowercase, 
   // contain no spaces, and include the prefix custpage if you are adding the button to
   // an existing page. For example, if you add a button that appears as Update Order, 
   // the button internal ID should be something similar to custpage_updateorder. 
   // ID must start with custpage
   
   // label - the display text of the button
   
   // script - assign the function of the script to be executed
   // There are a couple of options on how to set the script with the function to be called
   // 1. Assign the ID of a deployed script 
   // 2. Deploy a Client Side Script onto the record      
    
}

Create this function and deploy this as a script any type but ideally as a Client Side Script, in this scenario the script is also deployed within the User Event Script just to show it can be also set with a user event script

function onclick_callAlert(){
alert('This is the new button!');
// do other logic here
}

     Note: The button only execute scripts supported on the Client Side


DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations. NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto. NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

1 comment:

  1. acer laptops have much brighter lcd screens compared to other brands.. Event Production Company

    ReplyDelete