Name

sn_grc.GRCProfileListsBase

Description

Library for calculating related lists for Profiles

Script

var GRCProfileListsBase = Class.create();
GRCProfileListsBase.prototype = {
  initialize: function() {
      this.visited = {};
  },

  getParentsQuery: function(profileID) {
      return this._getParentsQuery(profileID);
  },

  getDownstreamProfileIDs: function(profileID) {
      return this._getDownstreamProfileIDs(profileID);
  },

  getValidDownstreamProfileIDs: function(profileID) {
      return this._getValidDownstreamProfileIDs(profileID);
  },

  getValidUpstreamProfileIDs: function(profileID) {
      return this._getValidUpstreamProfileIDs(profileID);
  },

  getDownstreamProfiles: function(profileID) {
      return this._getDownstreamProfiles(profileID);
  },

  getUpstreamProfiles: function(profileID) {
      return this._getUpstreamProfiles(profileID);
  },

  getDownstreamEngagmentIDs: function(profileID) {
      return this._getDownstreamEngagmentIDs(profileID);
  },
  
  getImmediateEngagmentIDs: function(profileID) {
      return this._getImmediateEngagmentIDs(profileID);
  },

  getDirectDownStreamProfiles: function(profileID) {
      return this._getDirectDownStreamProfiles(profileID);
  },

  getAlreadyAssociatedContent: function(entityId) {
      return this._getAlreadyAssociatedContent(entityId);
  },

  getRelationshipIds: function(entityId, relationshipType) {
      return this._getRelationshipIds(entityId, relationshipType);
  },

  checkUpstreamProfileRelatedList: function(listControlId){
  	return this._checkUpstreamProfileRelatedList(listControlId);
  },
  
  checkDownstreamProfileRelatedList: function(listControlId){
  	return this._checkDownstreamProfileRelatedList(listControlId);
  },
  
  getDownstreamCommonControlIds: function(profileIds) {
  	return this._getDownstreamCommonControlIds(profileIds);
  },
  
  _checkUpstreamProfileRelatedList: function(listControlId){
  	var listcontrol = new GlideRecord("sys_ui_list_control");
  	if(listcontrol.get(listControlId)){
  		var relatedListName = listcontrol.related_list;
  		if(relatedListName == "REL:0943d626b362320039da2cac16a8dccd"){
  			return true;
  		}
  	}
  	return false;
  },

  _checkDownstreamProfileRelatedList: function(listControlId){
  	var listcontrol = new GlideRecord("sys_ui_list_control");
  	if(listcontrol.get(listControlId)){
  		var relatedListName = listcontrol.related_list;
  		if(relatedListName == "REL:4eb63e17776d301048019eb58f5a9984"){
  			return true;
  		}
  	}
  	return false;
  },
  
  _getDownstreamEngagmentIDs: function(profileID) {
      var profileIDs = this._getDownstreamProfileIDs(profileID);
      var m2m = new GlideRecord('sn_audit_m2m_profile_engagement');
      m2m.addEncodedQuery('sn_grc_profileIN' + profileIDs);
      m2m.query();

      var engagementIDs = '';

      while (m2m.next())
          engagementIDs += ' ' + m2m.getValue('sn_audit_engagement');

      engagementIDs = (engagementIDs.trim()).replace(/ /g, ",");

      return engagementIDs;
  },
  
  _getImmediateEngagmentIDs: function(profileId) {
  	var m2m = new GlideRecord('sn_audit_m2m_profile_engagement');
      m2m.addEncodedQuery('sn_grc_profile=' + profileId);
      m2m.query();

      var engagementIDs = '';

      while (m2m.next())
          engagementIDs += ' ' + m2m.getValue('sn_audit_engagement');

      engagementIDs = (engagementIDs.trim()).replace(/ /g, ",");

      return engagementIDs;
  },

  _getValidDownstreamProfileIDs: function(profileID) {
      var downstreamIDs = [];
      this._getRelationshipIDs("children", [profileID], downstreamIDs, true);
      downstreamIDs.push(profileID);
      return downstreamIDs;
  },

  _getValidUpstreamProfileIDs: function(profileID) {
      var upstreamIDs = [];
      this._getRelationshipIDs("parents", [profileID], upstreamIDs, true);
      return upstreamIDs;
  },

  _getDownstreamProfiles: function(profileID) {
      var downstreamIDs = [];
      this._getRelationshipIDs("children", [profileID], downstreamIDs, false);
      downstreamIDs.push(profileID);
      return downstreamIDs;
  },

  _getUpstreamProfiles: function(profileID) {
      var upstreamIDs = [];
      this._getRelationshipIDs("parents", [profileID], upstreamIDs, false);
      return upstreamIDs;
  },

  _getDownstreamProfileIDs: function(profileID) {
      return (this._getDownstreamProfiles(profileID)).join(',');
  },

  _getParentsQuery: function(profileID) {
      upstreamIDs = (this._getUpstreamProfiles(profileID)).join(' ');
      var downstreamIDs = profileID + ' ' + upstreamIDs;

      downstreamIDs = downstreamIDs.replace(/ /g, "^ORdownstream_profile=");
      upstreamIDs = upstreamIDs.replace(/ /g, "^ORupstream_profile=");

      var query = 'upstream_profile=' + upstreamIDs + '^downstream_profile=' + downstreamIDs;
      return query;
  },


  _getRelationshipIDs: function(relationshipType, currentLevelProfiles, result, checkActive) {
      var streamDirection = 'upstream_profile';
      var oppositeDirection = 'downstream_profile';

      if (relationshipType == 'parents') {
          streamDirection = 'downstream_profile';
          oppositeDirection = 'upstream_profile';
      }
      var relationships = new GlideRecord('sn_grc_m2m_profile_profile');
      relationships.addQuery(streamDirection, "IN", currentLevelProfiles);
      relationships.query();
      var nextLevelProfiles = [];

      if (relationships.getRowCount() == 0)
          return;

      while (relationships.next()) {
          var profile = relationships.getValue(oppositeDirection);
          if ((!checkActive || relationships[oppositeDirection].active) && result.indexOf(profile) == -1) {
              nextLevelProfiles.push(profile);
              result.push(profile);
          }
      }
      this._getRelationshipIDs(relationshipType, nextLevelProfiles, result, checkActive);
  },

  _getDirectDownStreamProfiles: function(profileID) {
      var downstreamIDs = [];
      var relationships = new GlideRecord('sn_grc_m2m_profile_profile');
      relationships.addQuery('upstream_profile', profileID);
      relationships.addQuery('downstream_profile.active', true);
      relationships.query();

      while (relationships.next()) {
          downstreamIDs.push(relationships.downstream_profile + '');
      }

      return downstreamIDs;
  },

  _getAlreadyAssociatedContent: function(entityId) {
      var alreadyAssociatedContent = [];
      var gr = new GlideRecord('sn_grc_m2m_content_profile');
      gr.addQuery('sn_grc_profile', entityId);
      gr.query();

      while (gr.next())
          alreadyAssociatedContent.push(gr.getValue('sn_grc_content'));

      return alreadyAssociatedContent;
  },

  _getRelationshipIds: function(entityId, relationshipType) {

  	var streamDirection = 'upstream_profile';
      var oppositeDirection = 'downstream_profile';

      if (relationshipType == 'parents') {
          streamDirection = 'downstream_profile';
          oppositeDirection = 'upstream_profile';
      }
  	
      var m2mIds = [];

      var arr = new Array();
      arr.push(entityId);

      while (arr.length > 0) {
          var relationships = new GlideRecord('sn_grc_m2m_profile_profile');
          relationships.addQuery(streamDirection, 'IN', arr);
          relationships.query();

          arr = [];
          while (relationships.next()) {
              m2mIds.push(relationships.getUniqueValue());
              arr.push(relationships.getValue(oppositeDirection));

          }
      }
      return m2mIds;
  },
  
  _getDownstreamCommonControlIds: function(profileIds) {
  	var arr = profileIds.split(",");
  	var controlIds = [];
  	var inputParams = {
  			entityId: "",
  			itemType: "Control"
  		};
  	for(var i=0;i< arr.length; i++) {
  		inputParams["entityId"] = arr[i];
  		var response = new sn_grc.ItemInheritanceAPI().getItemsForReliantEntity(inputParams);
  		var commonControlsForEntity = response.itemIds;
  		if(commonControlsForEntity) {
  			controlIds = controlIds.concat(commonControlsForEntity.split(","));
  		}
  	}
  	
  	return controlIds.join(",");
  },

  type: 'GRCProfileListsBase'
};

Sys ID

7c961027b332320039da2cac16a8dc03

Offical Documentation

Official Docs: