Name
sn_hr_core.hr_DelegationBase
Description
No description available
Script
var hr_DelegationBase = Class.create();
hr_DelegationBase.prototype = {
initialize: function() {
this.DELEGATION_PLUGIN_ACTIVE = GlidePluginManager().isActive('com.glide.granular_service_delegation');
var maxRecordsReturned = gs.getProperty('sn_hr_core.delegation.max_records_returned_limit.override', '');
maxRecordsReturned = maxRecordsReturned && !isNaN(Number(maxRecordsReturned)) ? Number(maxRecordsReturned) : '';
this.MAX_DELEGATE_RECORD_RETURN = maxRecordsReturned;
},
/* Determine if user is assigned or delegated to a record
@param record - GlideRecord - The record to check if user is assigned or delegated to
@param userId - String - (optional) - The user to check if record is assigned or delegated to
@return Boolean - Whether or not the record is assigned or delegated to @param user
*/
isAssignedOrDelegated: function(record, userId) {
if (!record || !record.isValid())
return false;
if (!userId)
userId = gs.getUserID();
if (record.getElement('assigned_to').toString() == userId)
return true;
if (this.DELEGATION_PLUGIN_ACTIVE && new sn_delegation.DelegationUtil().isRecordDelegatedToUser(userId, record))
return true;
return false;
},
/* Determine if user is delegated to a record
@param record - GlideRecord - The record to check if user is delegated to
@param userId - String - (optional) - The user to check if record is delegated to
@return Boolean - Whether or not the record is delegated to @param user
*/
isDelegated: function(record, userId) {
if (!record || !record.isValid())
return false;
if (!userId)
userId = gs.getUserID();
if (this.DELEGATION_PLUGIN_ACTIVE && new sn_delegation.DelegationUtil().isRecordDelegatedToUser(userId, record))
return true;
return false;
},
/* Get the delegated assignments for a user
@param config - Object - Object describing delegation records to retrieve
{
@param tables - Array - (optional) - The tables to get delegated records from
@param start_date - String - (optional) - Get delegate records at or after this date
@param encoded_query - String - (optional) - The condition to filter delegated records
@param limit - Number - (optional) - The maximum number of records to get
}
@param userId - String - (optional) - The user to get delegated records for
@param includeUsersRecords - boolean (optional) - Include the users assigned records as well as delegated records
@return Array - An array of delegated record sys_id's
*/
getDelegatedTasks: function(config, userId, includeUserRecords) {
var delegatedRecords = [];
if (!this.DELEGATION_PLUGIN_ACTIVE)
return delegatedRecords;
var grTasks = this.getDelegatedTasksGR(config, userId, includeUserRecords);
while (grTasks.next())
delegatedRecords.push(grTasks.getUniqueValue());
return delegatedRecords;
},
/* Get the delegated assignments for a user
@param config - Object - Object describing delegation records to retrieve
{
@param tables - Array - (optional) - The tables to get delegated records from
@param start_date - String - (optional) - Get delegate records at or after this date
@param encoded_query - String - (optional) - The condition to filter delegated records
@param limit - Number - (optional) - The maximum number of records to get
}
@param userId - String - (optional) - The user to get delegated records for
@param includeUsersRecords - boolean (optional) - Include the users assigned records as well as delegated records
@return GlideRecord - Delegated records
*/
getDelegatedTasksGR: function(config, userId, includeUserRecords) {
if (!this.DELEGATION_PLUGIN_ACTIVE)
return new GlideRecord('task');
if (!userId)
userId = gs.getUserID();
if (this.MAX_DELEGATE_RECORD_RETURN !== '' && config && !config.hasOwnProperty('limit'))
config.limit = this.MAX_DELEGATE_RECORD_RETURN;
return new sn_delegation.DelegationUtil().getDelegatedAssignmentsForUser(userId, !!includeUserRecords, config);
},
/* Get the delegated approvals for a user
@param config - Object - Object describing delegation records to retrieve
{
@param tables - Array - (optional) - The tables to get delegated records from
@param start_date - String - (optional) - Get delegate records at or after this date
@param encoded_query - String - (optional) - The condition to filter delegated records
@param limit - Number - (optional) - The maximum number of records to get
}
@param userId - String - (optional) - The user to get delegated records for
@param includeUsersRecords - boolean (optional) - Include the users assigned records as well as delegated records
@return Array - An array of delegated record sys_id's
*/
getDelegatedApprovals: function(config, userId, includeUserRecords) {
var delegatedRecords = [];
if (!this.DELEGATION_PLUGIN_ACTIVE)
return delegatedRecords;
var grApprovals = this.getDelegatedApprovalsGR(config, userId, includeUserRecords);
while (grApprovals.next())
delegatedRecords.push(grApprovals.getUniqueValue());
return delegatedRecords;
},
/* Get the delegated approvals for a user
@param config - Object - Object describing delegation records to retrieve
{
@param tables - Array - (optional) - The tables to get delegated records from
@param start_date - String - (optional) - Get delegate records at or after this date
@param encoded_query - String - (optional) - The condition to filter delegated records
@param limit - Number - (optional) - The maximum number of records to get
}
@param userId - String - (optional) - The user to get delegated records for
@param includeUsersRecords - boolean (optional) - Include the users assigned records as well as delegated records
@return GlideRecord - Delegated records
*/
getDelegatedApprovalsGR: function(config, userId, includeUserRecords) {
if (!this.DELEGATION_PLUGIN_ACTIVE)
return new GlideRecord('sysapproval_approver');
if (!userId)
userId = gs.getUserID();
if (this.MAX_DELEGATE_RECORD_RETURN !== '' && config && !config.hasOwnProperty('limit'))
config.limit = this.MAX_DELEGATE_RECORD_RETURN;
return new sn_delegation.DelegationUtil().getDelegatedApprovalsForUser(userId, !!includeUserRecords, config);
},
/* Determine if user has an approval for a record
@param record - GlideRecord - The record to check for approvals for
@param userId - String - (optional) The user to check approvals for
@param includeUserRecords - boolean - (optional) Include the users assigned records as well as delegated records
*/
isApproverForRecord: function(record, userId, includeUserRecords) {
if (!this.DELEGATION_PLUGIN_ACTIVE || !record)
return false;
if (!userId)
userId = gs.getUserID();
if (includeUserRecords === undefined)
includeUserRecords = true;
var config = {};
config.encoded_query = 'sysapproval=' + record.getUniqueValue() + '^ORdocument_id=' + record.getUniqueValue();
config.limit = 1;
return this.getDelegatedApprovalsGR(config, userId, !!includeUserRecords).hasNext();
},
type: 'hr_DelegationBase'
};
Sys ID
7ef25e9dffc71010a9e7faf9453bf1fa