Name

sn_pa_center.AnalyticsCenterUtil

Description

Analytics Center utility function.

Script

var AnalyticsCenterUtil = Class.create();
AnalyticsCenterUtil.prototype = {
  initialize: function() {},

  //Create Analytics Center module for each workspace that doesn't have it.
  createAnalyticsCenterModule: function() {
      gs.info('Create Analytics Center Modules for existing workspaces - Start.');
      var wSList = this._getWorkspaceListThatDoesNotHaveAnalyticsCenter();

      if (wSList == null || wSList.length === 0) {
          gs.info('All existing workspaces have currently Analytics Center Module. No new module will be created.');
          return;
      }

      var desc = 'Following Analytics Center Modules were created:';
      for (var i = 0; i < wSList.length; i++) {
          var moduleId = this.createACModule(wSList[i]);
          desc += '\nWorkspace:' + wSList[i] + ' Analytics Center:' + moduleId;
      }
      gs.info(desc);
      gs.info('Create Analytics Center Modules for existing workspaces - End');
  },

  //Get list of all workspaces without Analytics center module
  _getWorkspaceListThatDoesNotHaveAnalyticsCenter: function() {
      var wSList = [];
      var hasACList = this._getWorkspaceListThatHasAnalyticsCenter();
      //Those WSs already have Analytics center module defined as part of the "if" folder
      var potentialWorkspacesToSkip = this._getWorkspacesToSkip();
      
      var skippedWSs = [];
      for (var i=0; i < potentialWorkspacesToSkip.length; i++) {
          if (hasACList.indexOf(potentialWorkspacesToSkip[i]) === -1) {
              hasACList.push(potentialWorkspacesToSkip[i]);
              skippedWSs.push(potentialWorkspacesToSkip[i]);
          }
      }
      gs.info('Following workspaces been skipped since they will have their Analytics Center module installed through the "IF" folder:' + skippedWSs);

      var gr = new GlideRecord('sys_aw_master_config');
      gr.query();
      while (gr.next()) {
          if (hasACList.indexOf(gr.getUniqueValue()) === -1)
              wSList.push(gr.getUniqueValue());

      }
      gs.info('Following workspaces does not have Analytics Center module:' + wSList);
      return wSList;
  },

  //Get list of all workspaces that have Analytics center module
  _getWorkspaceListThatHasAnalyticsCenter: function() {
      var list = [];
      var gr = new GlideRecord('sys_aw_module');
      gr.addEncodedQuery('id=analytics_center');
      gr.query();
      while (gr.next())
          list.push(gr.getValue('workspace_config'));

      gs.info('Following workspaces has already Analytics Center module:' + list);
      return list;
  },

  // Creates a new Analytics Center module for workspace with "workspaceSysId".
  // Returns the sys_id of the new created Module.
  createACModule: function(workspaceSysId) {
      var gr = new GlideRecord('sys_aw_module');
      if (!gr.get('18ffa6d63be23300b733ac20e2efc44e')) { //This is Analytics Center Module that is shipped with Analytics Center plugin
          gs.error('Analytics Center Module with SysId: 18ffa6d63be23300b733ac20e2efc44e could not be found!');
          return;
      }
      gr.setValue('active', true); //in case the module was set to inactive for any reason for workspace agent, we will set it active for this workspace
      gr.setValue('order', '1000'); //To display Analytics Center icon last in workspace
      gr.setValue('workspace_config', workspaceSysId);
      return gr.insert();
  },

  //Returns list of all installed WSs that has pre-defined AC moudle shipped under if folder
  _getWorkspacesToSkip: function() {
      var list = [];
      //Following workspaces has analytics center module defined for them under this path:
      //app-analytics-center/pa-analytics center/src/main/plugins/com.snc.pa.analytics_center/if
      //Therefore, we need to skip creating for them AC module as part of the fix migrate
      //script 'fix_add_analytics_center_module_to_workspace.xml' to avoid having 2 Analytics Center modules for same WS.
      //This is why we need to mark them as workspaces to skip creating AC module for them.
      var FINANCE_CLOSE_WORKSPACE_SYS_ID = 'fe3241b0736323007419c907fbf6a76f';
      var GRC_WORKSPACE_SYS_ID = 'bb551be5875133003058d1a936cb0b8f';
      var HR_WORKSPACE_SYS_ID = '6c8d4c7f5364330094fbddeeff7b125f';
      var LEGAL_COUNSEL_WORKSPACE_SYS_ID = '44406e7773003300844489b954f6a797';
      var MANAGER_WORKSPACE_SYS_ID = 'b47dea70b3210010ed7fc9c316a8dcf7';
      var SERVICE_WORKSPACE_SYS_ID = 'ff23c7f5b30323002a0862ac16a8dcc9';
      var VULNERABILITY_RESPONSE_WORKSPACE = '32107294533133004a77ddeeff7b1250';

      var sysIds = [];
      sysIds.push(FINANCE_CLOSE_WORKSPACE_SYS_ID);
      sysIds.push(GRC_WORKSPACE_SYS_ID);
      sysIds.push(HR_WORKSPACE_SYS_ID);
      sysIds.push(LEGAL_COUNSEL_WORKSPACE_SYS_ID);
      sysIds.push(MANAGER_WORKSPACE_SYS_ID);
      sysIds.push(SERVICE_WORKSPACE_SYS_ID);
      sysIds.push(VULNERABILITY_RESPONSE_WORKSPACE);

      var gr = new GlideRecord('sys_aw_master_config');
      gr.addEncodedQuery('sys_idIN' + sysIds.join());
      gr.query();
      while (gr.next())
          list.push(gr.getUniqueValue());

      return list;
  },

  type: 'AnalyticsCenterUtil'
};

Sys ID

9ed4a1743be20010ba51ac20e2efc4ef

Offical Documentation

Official Docs: