Name
sn_grc.GRCChoiceUtilsBase
Description
Utility functions for GRC Choices
Script
var GRCChoiceUtilsBase = Class.create();
GRCChoiceUtilsBase.prototype = {
initialize: function() {
this.setTableMap = {
'sn_compliance_authority_document' : 'authority_document',
'sn_compliance_citation' : 'citation',
'sn_compliance_policy' : 'policy',
'sn_compliance_control' : 'control_policy_statement',
'sn_compliance_policy_statement' : 'control_policy_statement',
'sn_risk_risk' : 'risk_risk_def',
'sn_risk_definition' : 'risk_risk_def',
'core_company' : 'vendor_risk',
'sn_vdr_risk_asmt_tiering_scale' : 'vendor_risk',
'sn_vdr_risk_asmt_def_tier_scale' : 'vendor_risk',
'sn_vdr_risk_asmt_tpss_rule' : 'vendor_risk',
'sn_vdr_risk_asmt_vendor_assessment_rule' : 'vendor_risk',
'sn_vdr_risk_asmt_vdr_tiering_assessment' : 'vendor_risk',
'advanced_risk' : 'advanced_risk',
'sn_vdr_risk_asmt_vendor_engagement' : 'vendor_risk',
'asmt_metric_type' : 'assessment_metric_type',
'sn_privacy_processing_activity' : 'processing_activity',
'sn_privacy_m2m_information_object_processing_activity' : 'info_object_to_pa',
'sn_irm_shared_cmn_document_access' : 'document_access'
};
},
getLocalizedChoices: function(table, field) {
return this._getLocalizedChoices(table, field);
},
findExistingChoice: function (targetTable, refRecord) {
var choice = this._getChoiceRecord(targetTable, refRecord);
if (choice.next())
return true;
return false;
},
getParentChoicesQualifier: function(current) {
return this._getParentChoicesQualifier(current);
},
_getParentChoicesQualifier: function(current) {
if (gs.nil(current.set))
return "";
var sysIds = [];
var set = String(current.set);
var currentSysId = current.getUniqueValue();
var choiceGR = new GlideRecord('sn_grc_choice');
choiceGR.addQuery('set', set);
choiceGR.addQuery('sys_id', '!=', currentSysId);
choiceGR.orderBy('choice_category');
choiceGR.query();
while (choiceGR.next())
sysIds.push(choiceGR.getUniqueValue());
return 'sys_idIN' + sysIds;
},
_getChoiceRecord: function(targetTable, refRecord) {
var choice = new GlideRecord('sn_grc_choice');
choice.addQuery('set', this.setTableMap[targetTable]);
choice.addQuery('name', refRecord.name + '');
choice.addQuery('label', refRecord.label + '');
choice.addQuery('choice_category', refRecord.choice_category + '');
choice.query();
return choice;
},
getGRCChoices: function(category, currClassName) {
return 'choice_category=' + category + '^set=' + this.setTableMap[currClassName];
},
getChoicesForField: function(targetTable, field, fieldValue) {
var choice = new GlideRecord('sn_grc_choice');
choice.addQuery('set', this.setTableMap[targetTable]);
choice.addQuery('choice_category', field);
choice.addQuery('label', fieldValue);
choice.query();
if(choice.next())
return choice.sys_id;
return '';
},
/**
* Retrieves translated choices for a given table and field
* @param {String} table - tableName
* @param {String} - choice fieldName
* @returns {Object}
*/
_getLocalizedChoices: function(table, field) {
var userLanguge = gs.getSession().getLanguage();
var choices = {};
//First fetch choices in english , this is because user might not have trnaslted every choice
var choiceRecords = new GlideRecord('sys_choice');
choiceRecords.addQuery('inactive', false);
choiceRecords.addQuery('name', table);
choiceRecords.addQuery('element', field);
choiceRecords.addQuery('language', 'en');
choiceRecords.orderBy('sequence');
choiceRecords.query();
while (choiceRecords.next()) {
var obj = {};
obj.label = choiceRecords.getValue('label');
obj.value = choiceRecords.getValue('value');
obj.hint = choiceRecords.getValue('hint');
choices[obj.value] = obj;
}
//If user language is not english then update labels and hints
if (userLanguge != 'en') {
choiceRecords = new GlideRecord('sys_choice');
choiceRecords.addQuery('inactive', false);
choiceRecords.addQuery('name', table);
choiceRecords.addQuery('element', field);
choiceRecords.addQuery('language', userLanguge);
choiceRecords.query();
while (choiceRecords.next()) {
var value = choiceRecords.getValue('value');
if (choices[value]) {
choices[value].label = choiceRecords.getValue('label');
choices[value].hint = choiceRecords.getValue('hint');
}
}
}
return choices;
},
type: 'GRCChoiceUtilsBase'
};
Sys ID
9f035556d7101200d77c83e80e6103f5