Thursday, April 25, 2019

Debugging Logs on Form-level and Client-side scripts

Adding debugging logs (also called Execution Logs) is necessary when troubleshooting codes or even in the middle of development.  Since Form-level scripts are not associated with Execution Logs, nlapiLogExecution API will not work.

Browsers such as Mozilla Firefox and Google Chrome support a global variable named console.  As an alternate solution, instead of displaying multiple alerts on the form, console.log and/or console.debug can be used to trace client scripts activities.

Sample code as follows:

     function jPageInit(type) {
          console.log('jPageInit fired');

          var roleId = nlapiGetRole();
          var hasTask = nlapiGetFieldValue('custentity_hastask');

          console.log(
               'Variables\n' +
               'type = ' + type + '\n' +
               'roleId = ' + roleId + '\n' +
               'hasTask = ' + hasTask
          );

          if ( type == 'edit' ) {
               console.log('Type is edit. Do some validations here....');
          }
          console.log('END of jPageInit');
     }


The figures below illustrates how to open the console using different browsers.

Google Chrome:

       [Screenshot Missing]



       [Screenshot Missing]




Mozilla Firefox:

       [Screenshot Missing]


 

No comments:

Post a Comment