Name
global.DocumentReferenceQualifiers
Description
This class contains methods that return reference qualifiers.
Script
var DocumentReferenceQualifiers = Class.create();
DocumentReferenceQualifiers.DOCUMENT_MANAGEMENT_USER_ROLE = "document_management_user";
DocumentReferenceQualifiers.getUserPermissionQualifier = function(){
return "roles=document_management_user";
};
DocumentReferenceQualifiers.getGroupPermissionQualifier = function(){
// PRB1320807: need to find two types of groups
// 1. the groups that contains "document_management_user" role directly
// 2. the groups that contains the role which include "document_management_user" role
var groupIds = [];
// First, find all roles that contains or equals to "document_management_user" role
var roles = DocumentReferenceQualifiers.findAllRolesThatIncludeCertainRole(DocumentReferenceQualifiers.DOCUMENT_MANAGEMENT_USER_ROLE);
// Second, find all groups that contains one of the roles we found above
var gr = new GlideRecord('sys_group_has_role');
gr.addEncodedQuery("role.nameIN" + roles.join(','));
gr.query();
while(gr.next()) {
groupIds.push(gr.getValue("group"));
}
return "sys_idIN" + groupIds.join(',');
};
DocumentReferenceQualifiers.findAllRolesThatIncludeCertainRole = function(role) {
var roles = [];// the array of role names
var rolesToBeQueried = [];
rolesToBeQueried.push(role);
while(rolesToBeQueried.length > 0) {
var temp = [];
for(var i = 0; i < rolesToBeQueried.length; i ++) {
roles.push(rolesToBeQueried[i]);
temp.push(rolesToBeQueried[i]);
}
rolesToBeQueried = [];
var grRC = new GlideRecord("sys_user_role_contains");
grRC.addEncodedQuery("contains.nameIN" + temp.join(","));
grRC.query();
while(grRC.next()) {
if (roles.indexOf(grRC.getDisplayValue("role")) == -1)
rolesToBeQueried.push(grRC.getDisplayValue("role"));
}
}
return roles;
};
DocumentReferenceQualifiers.getApproverQualifier = function(){
return "";
};
DocumentReferenceQualifiers.getUserQualifier = function(){
return "roles=document_management_user";
};
Sys ID
dadc333d0a0a2c7552cbd3f432e6e821