Create a multi-table processor

In this exercise, you will create a multi-table processor that reports the number of rows in any table on your instance.

About this task

The multi-table processor protects itself from performance and security violations by confirming that the user is authorized to read the table. It does not report on certain tables that are too large to query safely.

Procedure

  1. Navigate to System Definition > Processors.
    The list of processors appears.
  2. Click New.
  3. Enter the following information:
    Name TableSize
    Type Choose Javascript
    Description Return number of records in a table
    Parameters SIZE
    Path <leave empty>

    Script

    g_response.setContentType('text/html;charset=UTF-8');
    if(g_target === 'sys_email' || g_target === 'sys_log' ) 
    {
      g_processor.writeOutput(g_target + ' table is too large to quickly count');
      } else {   
        var count = new GlideAggregate(g_target);
        if( count.canRead() ) {
          count.addAggregate('COUNT');
          count.query();
          var records = 0;
          if (count.next()) {
            records = count.getAggregate('COUNT');
           }
           g_processor.writeOutput('table ' + g_target + ' has ' + records + ' records');
          } else {
           g_processor.writeOutput('You do not have access to table ' + g_target);
      }
    }            
  4. Click Save.
  5. Test the new processor by entering the following URLs:
    https://<instancename>.service-now.com/incident.do?SIZE
    https://<instancename>.service-now.com/sys_user.do?SIZE
    Your instance reports the number of records in the table. For example, table incident has 82 records.