Name

sn_grc.GRCItemGeneratorEngineBase

Description

NOTE This script include is deprecated. Generates items and links between documents and content

Script

var GRCItemGeneratorEngineBase = Class.create();
GRCItemGeneratorEngineBase.prototype = {

  initialize: function() {},

  generateLinks: function(record) {
      return this._getMethod(record, "generate");
  },

  deleteLinks: function(record) {
      this._getMethod(record, "delete");
  },

  createItemsForContent: function(record) {
      this._getMethod(record, "generateItems");
  },

  updateLinksForContent: function(record) {
      this._getMethod(record, "updateLinks");
  },

  deactivateProfileType: function(record) {
      this._deactivateProfileType(record, "deactivate");
  },

  _getMethod: function(record, operation) {
      var tableName;
      try {
          tableName = record.getRecordClassName();
      } catch (e) {
          tableName = record.tableName;
      }

      if (this._isInstanceOf("sn_grc_m2m_document_profile_type", tableName)) {
          this._setStrategy(tableName);
          if (operation == "generate")
              this._generateLinksDocToProfileType(record);
          else if (operation == "delete")
              this._deleteLinksDocToProfileType(record);
      } else if (this._isInstanceOf("sn_grc_content", tableName)) {
          this._setStrategy(tableName);
          if (operation == "generate")
              this._generateLinksContentToDoc(record);
          else if (operation == "delete")
              this._deleteLinksContentToDoc(record);
          else if (operation == "generateItems") {
              this._createItemsForContent(record);
              this._createItemsForContentToProfile(record);
          } else if (operation == "updateLinks")
              this._updateLinksForContent(record);
      } else if (this._isInstanceOf("sn_grc_m2m_document_content", tableName)) {
          this._setStrategy(tableName);
          if (operation == "generate")
              this._generateLinksforContentToDocM2m(record);
          else if (operation == "delete")
              this._deleteLinksforContentToDocM2m(record);
      } else if (this._isInstanceOf("sn_grc_document", tableName)) {
          this._setStrategy(tableName);
          this._deleteLinksDoc(record);
      } else if (this._isInstanceOf("sn_grc_m2m_content_profile_type", tableName)) {
          this._setStrategy(tableName);
          if (operation == "generate")
              this._generateItemsContentToProfileType(record);
          else if (operation == "delete")
              this._deleteSources(record, "contentToProfileType");
      } else if (this._isInstanceOf("sn_grc_m2m_content_profile", tableName)) {
          this._setStrategy(record.content_type);
          if (operation == "generate")
              return this._generateItemsContentToProfile(record);
          else if (operation == "delete") {
              this._deleteSources(record, "contentToProfile");
          }
      } else if (this._isInstanceOf("sn_grc_m2m_profile_profile_type", tableName)) {
          if (operation == "generate")
              this._generateItemsProfileToProfileType(record);
          else if (operation == "delete")
              this._deleteSources(record, "profileToProfileType");
      } else if (this._isInstanceOf("sn_grc_profile_type", tableName))
          this._deleteLinksProfileType(record);
      else if (this._isInstanceOf("sn_risk_m2m_risk_definition_policy_statement", tableName)) {
          if (operation == "generate")
              return this._generateLinksRisksToControls(record);
          else if (operation == "delete")
              this._deleteLinksRisksToControls(record);
      }
  },

  triggerDeleteEvent: function(record) {
      this._triggerDeleteEvent(record);
  },

  _triggerDeleteEvent: function(record) {
      gs.eventQueue('sn_grc.delete_links', null, record);
  },

  _generateLinksRisksToControls: function(record) {
      var utils = new ItemProcessingUtils();
      var riskStmt = record.sn_risk_definition;
      var policyStmt = record.sn_compliance_policy_statement;
      if (utils.addItemLinkProcessingRecord(riskStmt, policyStmt)) {

          var risk = new GlideRecord("sn_risk_risk");
          risk.addQuery("statement", riskStmt);

          var control = new GlideRecord("sn_compliance_control");
          control.addQuery("content", policyStmt);

          var lastAssociatedTime;
          if (record.last_associated_timestamp) {
              lastAssociatedTime = new GlideDateTime(record.last_associated_timestamp);
              risk.addQuery("sys_created_on", '>', lastAssociatedTime);
              control.addQuery("sys_created_on", '>', lastAssociatedTime);
          }

          risk.query();

          while (risk.next()) {
              var profileR = risk.profile;
              var controlP = new GlideRecord("sn_compliance_control");
              controlP.addQuery("profile", profileR);
              controlP.addQuery("content", policyStmt);
              controlP.query();
              while (controlP.next()) {
                  this._createLinksRisksToControls(controlP.sys_id, risk.sys_id);
              }
          }

          control.query();

          while (control.next()) {
              var profileC = control.profile;
              var riskP = new GlideRecord("sn_risk_risk");
              riskP.addQuery("profile", profileC);
              riskP.addQuery("statement", riskStmt);
              riskP.query();
              while (riskP.next()) {
                  this._createLinksRisksToControls(control.sys_id, riskP.sys_id);
              }
          }
          utils.removeItemLinkProcessingRecord(riskStmt, policyStmt);
          return true;
      } else {
          gs.addErrorMessage(gs.getMessage("Some error has been encountered"));
          return false;
      }

  },

  _createLinksRisksToControls: function(control, risk) {
      var controlToRisk = new GlideRecord("sn_risk_m2m_risk_control");
      controlToRisk.addQuery("sn_compliance_control", control);
      controlToRisk.addQuery("sn_risk_risk", risk);
      controlToRisk.query();
      if (!controlToRisk.next()) {
          controlToRisk.initialize();
          controlToRisk.sn_compliance_control = control;
          controlToRisk.sn_risk_risk = risk;
          controlToRisk.insert();
      }
  },

  _deleteLinksRisksToControls: function(m2mRecord) {
      var riskStmt = m2mRecord.sn_risk_definition;
      var policyStmt = m2mRecord.sn_compliance_policy_statement;
      var controlToRisk = new GlideRecord("sn_risk_m2m_risk_control");
      controlToRisk.addQuery("sn_compliance_control.content", policyStmt);
      controlToRisk.addQuery("sn_risk_risk.statement", riskStmt);
      controlToRisk.query();
      this._setStrategy(controlToRisk.getRecordClassName());
      this.strategy.deleteRecords(controlToRisk);
      new ItemProcessingUtils().removeItemLinkProcessingRecord(riskStmt, policyStmt);
  },

  _deleteLinksDoc: function(document) {
      var docToProfileTypeTable = this.strategy.getDocToProfileTypeTable();

      var doctoProfileType = new GlideRecord(docToProfileTypeTable);
      doctoProfileType.addQuery("sn_grc_document", document.sys_id);
      doctoProfileType.query();

      while (doctoProfileType.next())
          new ItemProcessingUtils().removeProcessingDocument(doctoProfileType.sn_grc_profile_type, doctoProfileType.sn_grc_document, 'retiring');

      doctoProfileType.query();

      this.strategy.deleteRecords(doctoProfileType);
  },

  _generateLinksDocToProfileType: function(m2mDocumentToProfileType) {
      var numStatusRecordsCreated = 0;

      numStatusRecordsCreated = this._createItemGenerationStatusRecords(m2mDocumentToProfileType);
      if (numStatusRecordsCreated == 0)
          new sn_grc.ItemProcessingUtils().removeProcessingDocument(
              m2mDocumentToProfileType.sn_grc_profile_type + '', m2mDocumentToProfileType.sn_grc_document + '', 'running');

      // Get the contents associated with the document
      this.strategy.linksDocToProfileType(m2mDocumentToProfileType, 'generate');
  },

  _deleteLinksDocToProfileType: function(m2mDocumentToProfileType) {
      if (!this.strategy.linksDocToProfileType(m2mDocumentToProfileType, 'delete'))
          new sn_grc.ItemProcessingUtils().removeProcessingDocument(m2mDocumentToProfileType.sn_grc_profile_type + '', m2mDocumentToProfileType.sn_grc_document + '', 'retiring');
  },

  _generateLinksforContentToDocM2m: function(contentToDoc) {
      var documentId = contentToDoc.document + '';

      // Get the profile types associated to the  document
      var docToProfileTypeTable = new GlideRecord(this.strategy.getDocToProfileTypeTable());
      docToProfileTypeTable.addQuery('sn_grc_document', documentId);
      docToProfileTypeTable.query();

      // Create the profile type to content link
      while (docToProfileTypeTable.next())
          this.strategy.generateLinksContentToProfileType(docToProfileTypeTable.sn_grc_document + '', contentToDoc.content, docToProfileTypeTable.sn_grc_profile_type);
  },

  _deleteLinksforContentToDocM2m: function(contentToDoc) {
      var content = new GlideRecord(this.strategy.getContentTable());
      content.get(contentToDoc.content + '');
      //Just remove releationship of document(policy) to content (policy statement), do not delte profiles or profile types
      //this._deleteLinksContentToDoc(content);
  },

  _generateLinksContentToDoc: function(content) {
      var documentIds = this.strategy.getDocumentsIds(content);

      // Get the profile types associated to the  document
      var docToProfileTypeTable = new GlideRecord(this.strategy.getDocToProfileTypeTable());
      docToProfileTypeTable.addQuery('sn_grc_document', 'IN', documentIds);
      docToProfileTypeTable.query();

      // Create the profile type to content link
      while (docToProfileTypeTable.next())
          this.strategy.generateLinksContentToProfileType(docToProfileTypeTable.sn_grc_document + '', content.sys_id, docToProfileTypeTable.sn_grc_profile_type);
      var gr = new GlideRecord('sn_grc_item_generation');
      if (gr.isValid()) {
          gr.addEncodedQuery('profileISEMPTY^profile_typeISEMPTY^content=' + content.sys_id);
          gr.query();
          if (gr.next()) {
              gr.deleteRecord();
          }
      }
  },

  _createItemsForContentToProfile: function(content) {
      var content_profile_m2m = new GlideRecord('sn_grc_m2m_content_profile');
      content_profile_m2m.addQuery('sn_grc_content', content.sys_id);
      content_profile_m2m.query();
      while (content_profile_m2m.next()) {
          new sn_grc.ItemProcessingUtils().addProcessContent(
              null, content.sys_id, 'running', null, content_profile_m2m.sn_grc_profile);
      }

      content_profile_m2m = new GlideRecord('sn_grc_m2m_content_profile');
      content_profile_m2m.addQuery('sn_grc_content', content.sys_id);
      content_profile_m2m.query();
      while (content_profile_m2m.next()) {
          this._generateItemsContentToProfile(content_profile_m2m);
      }
      var gr = new GlideRecord('sn_grc_item_generation');
      gr.addEncodedQuery('profileISEMPTY^profile_typeISEMPTY^content=' + content.sys_id)
      gr.query();
      if (gr.next()) {
          gr.deleteRecord();
      }
  },

  _createItemsForContent: function(content) {
      var contentToProfileType = new GlideRecord(this.strategy.getContentToProfileTypeTable());
      contentToProfileType.addQuery('sn_grc_content', content.sys_id);
      contentToProfileType.query();
      while (contentToProfileType.next()) {
          var profileTypeId = contentToProfileType.sn_grc_profile_type + '';
          var profiles = new GlideRecord('sn_grc_m2m_profile_profile_type');
          profiles.addQuery('profile_type', profileTypeId);
          profiles.query();
          while (profiles.next()) {
              new sn_grc.ItemProcessingUtils().addProcessContent(
                  profileTypeId, content.sys_id, 'running', null, profiles.getValue('profile'));
          }
          this._generateItemsContentToProfileType(contentToProfileType);
          new sn_grc.ItemProcessingUtils().removeProcessingContent(profileTypeId, content.sys_id, 'running');
      }
  },
  _updateLinksForContent: function(content) {
      //get all of the profile types associated with the previous document
      var profileType;
      var previousDoc = content.previous_document;
      var docToProfileType = new GlideRecord(this.strategy.getDocToProfileTypeTable());
      docToProfileType.addQuery('sn_grc_document', previousDoc);
      docToProfileType.query();
      while (docToProfileType.next()) {
          //find all of the relationships between those profile types and the content (one off false)
          profileType = docToProfileType.sn_grc_profile_type + '';

          //delete the relationship w/o workflow then delete the sources for each item
          if (this.strategy.deleteLinksContentToProfileType(docToProfileType.sn_grc_document, content.sys_id, profileType, false))
              this._deleteSources({
                  sn_grc_profile_type: profileType,
                  sn_grc_content: content.sys_id
              }, 'contentToProfileType');
      }

      //get all of the profile types associated with the current document
      var currentDoc = content.document;
      docToProfileType = new GlideRecord(this.strategy.getDocToProfileTypeTable());
      docToProfileType.addQuery('sn_grc_document', currentDoc);
      docToProfileType.query();
      while (docToProfileType.next()) {
          //add a processing record for each PT + content combo (with document)
          profileType = docToProfileType.sn_grc_profile_type + '';
          new sn_grc.ItemProcessingUtils().addProcessingContent(profileType, content.sys_id, 'running', currentDoc);
      }
      // generate links for the content
      this._generateLinksContentToDoc(content);
  },

  _deleteLinksContentToDoc: function(content) {
      var item = new GlideRecord("sn_grc_item");
      item.addQuery("content", content.sys_id);
      item.addActiveQuery();
      item.query();

      while (item.next())
          this._createRetirementStatus(item.getValue('profile'), content.sys_id, '', '');

      item = new GlideRecord("sn_grc_item");
      item.addQuery("content", content.sys_id);
      item.addActiveQuery();
      item.query();

      while (item.next()) {
          item.setValue("active", false);
          item.update();
          new GRCUtils().checkItemGenerationStatus(content.sys_id, item.getValue('profile'));
      }

      // Get the profile type to content records
      var contentToProfileType = new GlideRecord(this.strategy.getContentToProfileTypeTable());
      contentToProfileType.addQuery('sn_grc_content', content.sys_id);
      contentToProfileType.query();

      // Delete the content to profile type link
      while (contentToProfileType.next())
          this.strategy.deleteLinksContentToProfileType('', content.sys_id, contentToProfileType.sn_grc_profile_type);
  },

  _deleteLinksProfileType: function(profileType) {
      // Delete the document to profile type links
      this._deleteProfileTypeLinks("sn_grc_m2m_document_profile_type", profileType.sys_id);

      // Delete the content to profile type links
      this._deleteProfileTypeLinks("sn_grc_m2m_content_profile_type", profileType.sys_id);
  },

  _deleteProfileTypeLinks: function(m2mProfileTypeTable, profileTypeId) {
      var m2mProfileTypeTables = new GlideTableHierarchy(m2mProfileTypeTable).getTableExtensions();
      for (var item in m2mProfileTypeTables) {
          var m2mProfileType = new GlideRecord(m2mProfileTypeTables[item]);
          m2mProfileType.addQuery('sn_grc_profile_type', profileTypeId);
          m2mProfileType.query();

          this._setStrategy(m2mProfileType.getRecordClassName());
          this.strategy.deleteRecords(m2mProfileType);
      }
  },

  _generateItemsContentToProfileType: function(m2mContentToProfileType) {
      var profileTypeId = m2mContentToProfileType.sn_grc_profile_type;

      if (this.strategy.canCreateItems(m2mContentToProfileType.sn_grc_content)) {
          // Get the profiles associated with the profile type
          var profileToProfileType = new GlideRecord('sn_grc_m2m_profile_profile_type');
          profileToProfileType.addQuery('profile_type', profileTypeId);
          profileToProfileType.query();

          // GRC PA
          var paContentIndicatorList = {};

          if (GlidePluginManager.isActive('com.sn_grc_pa'))
              paContentIndicatorList = (new sn_grc_pa.GRCPAIndicatorUtils()).getIndicatorBreakdownList(m2mContentToProfileType.sn_grc_content);

          while (profileToProfileType.next()) {
              var itemId = this._generateItem(m2mContentToProfileType.sn_grc_content, profileToProfileType.profile, profileTypeId);

              if (GlidePluginManager.isActive('com.sn_grc_pa')) {
                  var item = new GlideRecord("sn_grc_item");
                  if (itemId != "" && item.get(itemId))
                      for (var paContentIndicatorId in paContentIndicatorList)
                          (new sn_grc_pa.GRCPAIndicatorUtils()).generatePAIndicatorItemRelationship(item, paContentIndicatorId, paContentIndicatorList[paContentIndicatorId]);
              }
          }
      }

      // This deletion is a stop gap that guarantees that the "processors" for empty"
      // relationships that generate no items will be deleted
      if (this.strategy.getContentTable() == "sn_risk_definition") {
          var document = m2mContentToProfileType.created_one_off ? '' : m2mContentToProfileType.sn_grc_content.document;
          new sn_grc.ItemProcessingUtils().removeProcessingContent(
              profileTypeId, m2mContentToProfileType.sn_grc_content, 'running', document);
      } else {
          if (m2mContentToProfileType.created_one_off)
              new sn_grc.ItemProcessingUtils().removeProcessingContent(
                  profileTypeId, m2mContentToProfileType.sn_grc_content, 'running', '');
          else {
              var sources = m2mContentToProfileType.source.split(",");

              for (var i = 0; i < sources.length - 1; i++)
                  new sn_grc.ItemProcessingUtils().removeProcessingContent(
                      profileTypeId, m2mContentToProfileType.sn_grc_content, 'running', sources[i]);
          }
      }
  },

  _generateItemsContentToProfile: function(m2mContentToProfile) {
      var profileId = m2mContentToProfile.sn_grc_profile;
      var itemId = "";
      if (this.strategy.canCreateItems(m2mContentToProfile.sn_grc_content)) {
          itemId = this._generateItem(m2mContentToProfile.sn_grc_content, profileId, profileId);
      }
      return itemId;
  },

  _deleteSources: function(m2m, type) {
      // Get the items associated with the content/ profile
      var sourceId = null;
      var item = new GlideRecord("sn_grc_item");
      if (type == "contentToProfileType") {
          sourceId = m2m.sn_grc_profile_type;
          this._createItemRetiringStatus(m2m.sn_grc_profile_type, m2m.sn_grc_content, '');
          item.addQuery('content', m2m.sn_grc_content);
          item.addQuery('source', 'CONTAINS', m2m.sn_grc_profile_type);
      } else if (type == "contentToProfile") {
          sourceId = m2m.sn_grc_profile;
          this._createItemRetiringStatus('', m2m.sn_grc_content, m2m.sn_grc_profile);
          item.addQuery('content', m2m.sn_grc_content);
          item.addQuery('source', 'CONTAINS', m2m.sn_grc_profile);
      } else if (type == "profileToProfileType") {
          sourceId = m2m.profile_type;
          item.addQuery('profile', m2m.profile);
          item.addQuery('source', 'CONTAINS', m2m.profile_type);
      }
      item.query();

      var source = "";
      while (item.next()) {
          if (item.getValue("source") != null) {
              source = item.getValue("source") + "";
              source = source.replace(sourceId + ",", "");
              item.setValue("source", source);
              if (source == "") {
                  item.state = 'retired';
                  item.active = false;
              }
              item.update();
              var statuses = new GlideRecord('sn_grc_item_generation');
              statuses.addQuery('content', item.content);
              statuses.addQuery('profile', item.profile);
              statuses.addQuery('running', 'retiring');
              statuses.setLimit(1);
              statuses.query();
              if (statuses.next()) {
                  statuses.deleteRecord();
              }
          }
      }
      if (type == "contentToProfile")
          return new sn_grc.ItemProcessingUtils().removeProcessingContent(null, m2m.sn_grc_content, 'retiring', null, m2m.sn_grc_profile);
      else {
          var pt = new GlideRecord("sn_grc_profile_type");
          pt.get(sourceId);
          if (!pt.isValidRecord()) {
              new sn_grc.ItemProcessingUtils().removeProcessingContent('', m2m.sn_grc_content, 'retiring');
          }
      }
      new sn_grc.ItemProcessingUtils().removeProcessingContent(sourceId, m2m.sn_grc_content, 'retiring');
  },

  _createItemRetiringStatus: function(profileTypeId, contentId, profileId) {

      var sourceId;
      var item = new GlideRecord("sn_grc_item");
      item.addQuery('content', contentId);
      item.addEncodedQuery('stateNOT INretired');
      item.query();
      if (profileTypeId != '') {
          sourceId = profileTypeId;
      } else {
          sourceId = profileId;
      }
      var numRecordsToBeRetired = 0;
      while (item.next()) {
          // if only have one source, create a retirement status for it if one isn't already created
          var retStatus;
          if (item.source + '' == sourceId + ',') {
              numRecordsToBeRetired++;
              retStatus = new GlideRecord('sn_grc_item_generation');
              retStatus.addQuery('profile', item.profile);
              retStatus.addQuery('content', item.content);
              if (profileTypeId != '')
                  retStatus.addQuery('profile_type', profileTypeId);
              retStatus.setLimit(1);
              retStatus.query();
              if (!retStatus.next())
                  this._createRetirementStatus(item.getValue('profile'), item.getValue('content'), '', profileTypeId);
          } else {
              // Delete the retirement statuses for records that aren't retiring
              // because they still have sources
              retStatus = new GlideRecord('sn_grc_item_generation');
              retStatus.addQuery('profile', item.profile + '');
              retStatus.addQuery('content', item.content + '');
              retStatus.addQuery('running', 'retiring');
              retStatus.query();
              retStatus.deleteMultiple();
          }
      }
  },

  _generateItemsProfileToProfileType: function(m2mProfileToProfileType) {
      // Get all the contents attached to the profile type
      var contentToProfileTypeTables = new GlideTableHierarchy("sn_grc_m2m_content_profile_type").getTableExtensions();
      for (var item in contentToProfileTypeTables) {
          var profileTypeId = m2mProfileToProfileType.profile_type;

          // Get contents
          var contentToProfileType = new GlideRecord(contentToProfileTypeTables[item]);
          contentToProfileType.addQuery('sn_grc_profile_type', profileTypeId);
          contentToProfileType.query();

          this._setStrategy(contentToProfileType.getRecordClassName());
          while (contentToProfileType.next()) {
              if (this.strategy.canCreateItems(contentToProfileType.sn_grc_content))
                  this._generateItem(contentToProfileType.sn_grc_content, m2mProfileToProfileType.profile, profileTypeId);
          }
      }
  },

  _generateItem: function(contentId, profileId, source) {
      var contentTable = this.strategy.getContentTable();

      var content = new GlideRecord(contentTable);
      content.get(contentId);

      var profile = new GlideRecord("sn_grc_profile");
      profile.get(profileId);

      return this.strategy.generateItem(profile, content, source);
  },

  _isInstanceOf: function(baseTableName, tableName) {
      var hierarchy = new GlideTableHierarchy(baseTableName).getHierarchy();
      return new global.ArrayUtil().contains(hierarchy, tableName);
  },

  _setStrategy: function(tableName) {
      if (tableName.match("sn_risk"))
          this.strategy = new sn_risk.RiskGeneratorStrategy();
      else if (tableName.match("sn_compliance"))
          this.strategy = new sn_compliance.ControlGeneratorStrategy();
  },

  _createItemGenerationStatusRecords: function(record) {
      var document = record.sn_grc_document;
      var pType = record.sn_grc_profile_type;

      var profileM2M = new GlideRecord('sn_grc_m2m_profile_profile_type');
      profileM2M.addQuery('profile_type', pType);
      profileM2M.query();

      var statementIds = [];
      var status;
      var index;

      var numStatusRecordsCreated = 0;
      while (profileM2M.next()) {
          var profile = profileM2M.profile;
          statementIds = this.strategy.getStatementIds(document);

          while (index in statementIds) {
              // Don't create status records for content that won't
              // generate items
              if (!this.strategy.canCreateItems(statementIds[index]))
                  continue;

              // Don't create status records for items that already
              // exist and are active
              var item = new GlideRecord('sn_grc_item');
              item.addQuery('profile', profile);
              item.addQuery('content', statementIds[index]);
              item.addActiveQuery();
              item.setLimit(1);
              item.query();
              if (item.hasNext())
                  continue;

              status = new GlideRecord('sn_grc_item_generation');
              status.profile_type = pType;
              status.profile = profile;
              status.document = document;
              status.content = statementIds[index];
              status.running = 'ready';
              status.insert();
              numStatusRecordsCreated++;
          }
      }
      return numStatusRecordsCreated;
  },

  _createRetirementStatus: function(profileID, contentID, documentID, profileTypeID) {
      var status = new GlideRecord('sn_grc_item_generation');
      if (profileTypeID != '')
          status.setValue('profile_type', profileTypeID);

      if (documentID != '')
          status.setValue('document', documentID);

      status.setValue('content', contentID);
      status.setValue('profile', profileID);
      status.setValue('running', 'retiring');
      status.insert();
  },

  _deactivateProfileType: function(profileType) {
      var relatedContentId;
      var relatedDocIds = this._deletePTRelationships(profileType, 'sn_grc_m2m_document_profile_type', 'sn_grc_document');
      var relatedContentIds = this._deletePTRelationships(profileType, 'sn_grc_m2m_content_profile_type', 'sn_grc_content', 'document');
      for (relatedContentId in relatedContentIds)
          this._deleteSources({
              sn_grc_profile_type: profileType.sys_id,
              sn_grc_content: relatedContentId
          }, 'contentToProfileType');
      new GRCUtils().checkProfilesForDeactivation(profileType);
      for (relatedContentId in relatedContentIds)
          new sn_grc.ItemProcessingUtils().removeProcessingContent(profileType.sys_id, relatedContentId, 'retiring', relatedContentIds[relatedContentId]);

      for (var relatedDocId in relatedDocIds)
          new sn_grc.ItemProcessingUtils().removeProcessingDocument(profileType.sys_id, relatedDocId, 'retiring');
  },

  _deletePTRelationships: function(profileType, m2mTableName, m2mFieldName, valueFieldName) {
      var relatedRecordIds = {};
      var relatedRecordTables = new GlideTableHierarchy(m2mTableName).getTableExtensions();
      for (var item in relatedRecordTables) {
          var relatedRecord = new GlideRecord(relatedRecordTables[item]);
          relatedRecord.addQuery('sn_grc_profile_type', profileType.sys_id);
          relatedRecord.query();
          while (relatedRecord.next()) {
              this._setStrategy(relatedRecord.getRecordClassName());
              this.strategy.deleteRecords(relatedRecord, false);
              if (valueFieldName != null)
                  relatedRecordIds[relatedRecord[m2mFieldName]] = relatedRecord[m2mFieldName][valueFieldName];
              else
                  relatedRecordIds[relatedRecord[m2mFieldName]] = true;
          }
      }
      return relatedRecordIds;
  },

  type: 'GRCItemGeneratorEngineBase'
};

Sys ID

952d83622f3202007eaf77cfb18c9503

Offical Documentation

Official Docs: