Name

global.CreatedByNOW

Description

Gets installed as the script for the CreatedByNOW share project. Our little script to check if the record is created by NOW and modified by us. new CreatedByNOW().touched() new CreatedByNOW().untouched()

Script

var CreatedByNOW = Class.create();
CreatedByNOW.prototype = {
  initialize: function() {
      this.ourAppCode = 'x_' + gs.getProperty('glide.appcreator.company.code'); // Our app
  },

  hasAnyVersionRecord: function() {
      var version = new GlideRecord('sys_update_version');
      version.addQuery('name', current.sys_update_name);  // history for the current record
      version.setLimit(1);                                // just need one
      version.orderByDesc('sys_updated_on');              // the most recent
      version.query();
      if (version.getRowCount() == 0) // No version records!
          return false;
      version.next();
      if (version.state == 'current' && version.source_table == 'sys_upgrade_history') // Reverted record
          return false;
      return true; // Has version records other than a system upgrade history as current
  },

  untouched: function() {
      // Check the package source for the customer application
      if (current.sys_package.source.indexOf(this.ourAppCode) > -1)
          return false;

      // Check for untouched ServiceNow record
      if (this.hasAnyVersionRecord())
          return false;
      return true;
  },

  hasUpgradeVersions: function() {
      var version = new GlideRecord('sys_update_version');
      version.addQuery('name', current.sys_update_name); // history for the current record
      version.addQuery('source_table', 'sys_upgrade_history'); // look for upgrade history
      // version.addQuery('application.scope', 'NOT LIKE', this.ourAppCode + '%'); // filter out our app
      version.setLimit(1);                               // just need one
      version.orderByDesc('sys_updated_on');             // the most recent
      version.query();
      if (version.getRowCount() == 0) // No version records!
          return false;
      version.next();
      if (version.state == 'current') // Touched but reverted
          return false;
      return true; // upgrade versions exist in the history 
  },

  touched: function() {
      // Check the package source for our customer application
      if (current.sys_package.source.indexOf(this.ourAppCode) > -1)
          return false;
  	
      // If we touched it, at least one version record will exist
  	// and the current record is not a sys_upgrade_history source table.
      return this.hasUpgradeVersions(); // Return true for touched /false for untouched
  },

  type: 'CreatedByNOW'
};

Sys ID

e4afdaccdba6a45055bb2c23ca96196f

Offical Documentation

Official Docs: