How to use Client Script functions like saveRecord, PageInit on a Suitelet form

 In this post we are going to see how we can use standard client script triggers like saveRecord and pageInit on a adhoc client script  that is attached to a suitelet form.

From below code you will find that we can not only use our custom function code in client script but also standard Netsuite functions like saveRecord and pageInit as well along with custom code and this client script is not deployed but it is just in file cabinet of suitescript folder. 

Client Script Code: 

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */

define([ 'N/record' ],function(record){
    function pageInit(){
        
	alert("This is PageInit");
    }
  
    function saveRecord(){
      alert("save Record")
      return true;
    }
    
    function customFun(){
      alert("customFun")
    }
    return {
         pageInit: pageInit,
         saveRecord: saveRecord,
         customFun: customFun
    }
});

Suitelet Code: 

/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(['N/email', 'N/runtime', 'N/ui/serverWidget'], function(email, runtime, serverWidget) {
    function onRequest(context) {
        if (context.request.method === 'GET') {
            var form = serverWidget.createForm({
                title: 'Message Form'
            });

            var message = form.addField({
                id: 'message',
                type: serverWidget.FieldType.TEXTAREA,
                label: 'Message'
            });
            message.updateDisplaySize({
                height: 10,
                width : 60
            });

            form.addSubmitButton({
                label: 'Send Message'
            });
          
            form.addButton({
               label: "custom Button",
               id: "button1",
               functionName: "customFun"
            })
          
            form.clientScriptModulePath = 'SuiteScripts/testClientScript.js';

            context.response.writePage(form);
			
			
        }
        else
        {
            var message = context.request.parameters.message;
            context.response.write(message);
        }
    }

    return {
        onRequest: onRequest
    };
});


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *