Name
sn_grc.GRCScopingUseQueryService
Description
No description available
Script
var GRCScopingUseQueryService = Class.create();
GRCScopingUseQueryService.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
createProfilesAndTypes: function() {
var queryInfo = this.getParameter('sysparm_query_info');
var contentId = this.getParameter('sysparm_contentId');
var contentName = this.getParameter('sysparm_contentName');
var ptName = this.getParameter('sysparm_profileTypeName');
var queryInfoArr = new global.JSON().decode(queryInfo);
// Create profile type
var pt = new GlideRecord('sn_grc_profile_type');
pt.name = ptName == ''? gs.getMessage('Empty') : ptName;
pt.processing_profiles = false;
if (pt.canCreate()) {
var ptId = pt.insert();
}
// Create m2m between profile type and content
var m2m;
if (contentName == 'sn_compliance_policy_statement') {
m2m = new GlideRecord('sn_compliance_m2m_statement_profile_type');
m2m.sn_compliance_statement = contentId;
}
else if (contentName == 'sn_risk_definition') {
m2m = new GlideRecord('sn_risk_m2m_risk_definition_profile_type');
m2m.statement = contentId;
}
m2m.sn_grc_profile_type = ptId;
if (m2m.canCreate()) {
m2m.insert();
}
for (var i = 0; i < queryInfoArr.length; i++) {
var tableName = queryInfoArr[i].table;
var encodedQuery = queryInfoArr[i].query;
// Create enrichment query
var q = new GlideRecord('sn_grc_enrichment_query');
q.name = tableName;
q.table = tableName;
if (encodedQuery)
q.condition = encodedQuery;
q.use_owner_field = false;
q.need_update = false;
q.profile_type = ptId;
if (q.canCreate()) {
q.insert();
}
}
// Generate profiles
if (!ptId)
return new global.JSON().encode('error');
var profileType = new GlideRecord('sn_grc_profile_type');
if (!profileType.get(ptId))
return new global.JSON().encode('error');
profileType.processing_profiles = true;
if (profileType.canWrite()) {
profileType.update();
}
gs.eventQueue('sn_grc.generating_profiles', null, ptId);
return new global.JSON().encode(ptId);
},
type: 'GRCScopingUseQueryService'
});
Sys ID
3cedc646d7000300bbc783e80e610397