Name

sn_install_base.InstallBaseFilterSNC

Description

No description available

Script

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

  isHouseholdPluginActive: function() {
      return GlidePluginManager.isActive(global.CSMBaseConstants.HOUSEHOLD_PLUGIN);
  },

  isServiceOrganizationPluginActive: function() {
      return GlidePluginManager.isActive(global.CSMBaseConstants.SERVICE_ORGANIZATION_PLUGIN);
  },

  isB2B2CPluginActive: function() {
      return GlidePluginManager.isActive(global.CSMBaseConstants.B2B2C_PLUGIN);
  },

  /*
  This method returns an encoded query for install base items considering the primary fields 
  (i.e. contact,account,consumer,household,service organization) and the related 
  parties (i.e. Authorised Contact, Authorised Consumer).
  */

  getRefQualifierForIBonCase: function(inputVars) {
      var ibSysIDs = [];
      var q1 = this.getIBsFromPrimaryFields(inputVars);
      var q2 = this.getIBsFromRelatedParties(inputVars);

      if (gs.nil(q1) && gs.nil(q2))
          return '';

      if (!gs.nil(q1) && q1 != '') {
          var ibsWithGivenUserAsOwner = new GlideRecord(global.CSMBaseConstants.INSTALL_BASE_ITEM);
          ibsWithGivenUserAsOwner.addEncodedQuery(q1);
          ibsWithGivenUserAsOwner.query();
          while (ibsWithGivenUserAsOwner.next()) {
              ibSysIDs.push(ibsWithGivenUserAsOwner.getUniqueValue());
          }
      }

      if (!gs.nil(q2) && q2 != '') {
          var ibsWithGivenUserAsRelatedParty = new GlideRecord(global.CSMBaseConstants.INSTALL_BASE_ITEM);
          ibsWithGivenUserAsRelatedParty.addEncodedQuery(q2);
          ibsWithGivenUserAsRelatedParty.query();
          while (ibsWithGivenUserAsRelatedParty.next()) {
              ibSysIDs.push(ibsWithGivenUserAsRelatedParty.getUniqueValue());
          }
      }

      var encodedQuery = 'sys_id' + 'IN' + ibSysIDs.join(',');
      return encodedQuery;
  },

  getIBsFromPrimaryFields: function(inputVars) {
      var encodedQuery = '';
      if (inputVars[global.CSMBaseConstants.ACCOUNT_TABLE]) {
          encodedQuery += 'account=' + inputVars[global.CSMBaseConstants.ACCOUNT_TABLE];
          var isAccessRestricted = new global.Account().isRestrictedAccessAccount(inputVars[global.CSMBaseConstants.ACCOUNT_TABLE]);
          if (inputVars[global.CSMBaseConstants.CONTACT_TABLE]) {
              var contactHasCustomerAdminRole = new global.CSHelper().userHasRole(inputVars[global.CSMBaseConstants.CONTACT_TABLE], "sn_customerservice.customer_admin");
              if (isAccessRestricted && !contactHasCustomerAdminRole) {
                  encodedQuery += '^contact=' + inputVars[global.CSMBaseConstants.CONTACT_TABLE];
              }
          }
          if (inputVars[global.CSMBaseConstants.CONSUMER_TABLE] && this.isB2B2CPluginActive())
              encodedQuery += '^consumer=' + inputVars[global.CSMBaseConstants.CONSUMER_TABLE];
      } else if (inputVars[global.CSMBaseConstants.CONSUMER_TABLE] || inputVars[global.CSMBaseConstants.HOUSEHOLD]) {
          if (inputVars[global.CSMBaseConstants.CONSUMER_TABLE]) {
              qr = 'consumer=' + inputVars[global.CSMBaseConstants.CONSUMER_TABLE];
              if (this.isHouseholdPluginActive()) {
                  var householdIds = new sn_csm_household.HouseHoldUtils().getHouseholdsUnderConsumer(inputVars[global.CSMBaseConstants.CONSUMER_TABLE]);
                  if (householdIds.length > 0)
                      qr += '^OR' + 'household' + 'IN' + householdIds.join(',');
              }
              encodedQuery += qr;
          }
          if (this.isHouseholdPluginActive() && inputVars[global.CSMBaseConstants.HOUSEHOLD]) {
              if (encodedQuery == '')
                  encodedQuery += 'household=' + inputVars[global.CSMBaseConstants.HOUSEHOLD];
              else
                  encodedQuery += '^household=' + inputVars[global.CSMBaseConstants.HOUSEHOLD];
          }
      } else if (this.isServiceOrganizationPluginActive() && inputVars[global.CSMBaseConstants.SERVICE_ORGANIZATION_TABLE]) {
          encodedQuery += 'service_organization=' + inputVars[global.CSMBaseConstants.SERVICE_ORGANIZATION_TABLE];
      }

      return encodedQuery;
  },

  getIBsFromRelatedParties: function(inputVars) {
      var encodedQuery = '';
      var relatedPartyTable = global.CSMBaseConstants.INSTALL_BASE_RELATED_PARTY;
      var field = 'install_base_item';
      var params = {
          'responsibility': null,
          'access': 'FULL'
      };

      var validGRSysIdsFromRelatedParty = [];
      var glideRecord = new GlideRecordSecure(global.CSMBaseConstants.INSTALL_BASE_ITEM);
      if (!gs.nil(inputVars[global.CSMBaseConstants.CONTACT_TABLE])) {
          /* AUTHORISED CONTACT */
          var ibSysIdsForAuthorisedContact = new sn_install_base.InstallBaseUtil().getAllEntities(inputVars[global.CSMBaseConstants.CONTACT_TABLE], params);
          glideRecord.addQuery('sys_id', 'IN', ibSysIdsForAuthorisedContact.join(',')).addOrCondition('root', 'IN', ibSysIdsForAuthorisedContact.join(','));
          glideRecord.addQuery('account', inputVars[global.CSMBaseConstants.ACCOUNT_TABLE]);

      } else if (gs.nil(inputVars[global.CSMBaseConstants.ACCOUNT_TABLE]) && !gs.nil(inputVars[global.CSMBaseConstants.CONSUMER_TABLE])) {
          /* AUTHORISED CONSUMER */
          encodedQuery += 'consumer!=NULL';
          if (this.isHouseholdPluginActive())
              encodedQuery += '^ORhousehold!=NULL';
          var ibSysIdsForAuthorisedConsumer = new sn_install_base.InstallBaseUtil().getAllEntities(inputVars[global.CSMBaseConstants.CONSUMER_TABLE], params);
          glideRecord.addQuery('sys_id', 'IN', ibSysIdsForAuthorisedConsumer.join(',')).addOrCondition('root', 'IN', ibSysIdsForAuthorisedConsumer.join(','));
      }

      if (glideRecord.getEncodedQuery() != '') {
          glideRecord.query();
          while (glideRecord.next()) {
              validGRSysIdsFromRelatedParty.push(glideRecord.getUniqueValue());
          }
      }

      if (validGRSysIdsFromRelatedParty.length > 0) {
          if (encodedQuery == '')
              encodedQuery += 'sys_idIN' + validGRSysIdsFromRelatedParty.join(',');
          else
              encodedQuery += '^sys_idIN' + validGRSysIdsFromRelatedParty.join(',');
      } else
          encodedQuery = '';

      return encodedQuery;
  },

  type: 'InstallBaseFilterSNC'
};

Sys ID

1b0a587443e52110a7da21e1c9b8f21d

Offical Documentation

Official Docs: