Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Hide requests from 'My Requests' tab on EC Pro for HR Task Assigned to users

Kashmira Surana
Tera Contributor

Hello All,

Here is my scenario:

 

If a HR Case has a HR task associated and that HR Task is assigned to a user then that user must see only HR Tasks in "My tasks" tab He/She should not see the requests under "MY Requests" tab on EC Pro.

Could anyone please guide on this. Will Appreciate your help.

Thank you.

2 REPLIES 2

Shruti
Mega Sage
Mega Sage

Hi,

You need to remove below highlighted lines of code from OOB script include hr_caseMyRequestFilterUtil.

Since it is OOB script include. I would suggest to follow the best practice to inactivate the OOB script include and create a copy of it via "Insert and stay" and comment out below highlighted code 

 

 

var hr_caseMyRequestFilterUtil = Class.create();

//HR Case Extension Tables
hr_caseMyRequestFilterUtil.hrCaseTables = sn_hr_core.hr.TABLE_CASE_EXTENSIONS.toString();

hr_caseMyRequestFilterUtil.prototype = {
initialize: function() {
this._user = gs.getUserID();
this.cases = [];
},

hr_caseMyRequestFilter: function(checkCompleted) {

var grCase = new GlideRecord('sn_hr_core_case');
grCase.addQuery('opened_for', this._user).addOrCondition('hr_service.subject_person_access', true).addCondition('subject_person', this._user);
grCase.addQuery('state', '!=', hr_Constants.CASE_DRAFT);
if (checkCompleted) {
grCase.addQuery('active', 'false');
grCase.addNotNullQuery('closed_at');
} else
grCase.addActiveQuery();

grCase.orderBy('number');
grCase.query();
while (grCase.next())
this._hrCaseParent(grCase, checkCompleted);
/*
var grTask = new GlideRecord('sn_hr_core_task');
grTask.addQuery('assigned_to', this._user);
grTask.addQuery('state', '!=',hr_Constants.TASK_DRAFT);
grTask.addQuery('parent.sys_class_name', 'INSTANCEOF', 'sn_hr_core_case');
grTask.addQuery('parent.state', '!=',hr_Constants.CASE_DRAFT);
if (checkCompleted) {
grTask.addQuery('active', 'false');
grTask.addNotNullQuery('closed_at');
grTask.addQuery('parent.active', 'false');
grTask.orderByDesc('parent.closed_at');
} else {
grTask.addQuery('parent.active', 'true');
grTask.orderBy('number');
}
grTask.query();
while (grTask.next()) {
var grCaseParent = grTask.parent.getRefRecord();
this._hrCaseParent(grCaseParent, checkCompleted);
}

if (GlidePluginManager.isActive('com.snc.document_templates')) {
var grTask = new GlideRecord('sn_doc_task');
grTask.addQuery('assigned_to', this._user);
grTask.addQuery('state', '!=', hr_Constants.DOCTASK_DRAFT);
grTask.addQuery('parent.sys_class_name', 'INSTANCEOF', 'sn_hr_core_case');
grTask.addQuery('parent.state', '!=', hr_Constants.CASE_DRAFT);
if (checkCompleted) {
var inQuery=[hr_Constants.DOCTASK_CLOSED_COMPLETE,hr_Constants.DOCTASK_CLOSED_INCOMPLETE,hr_Constants.DOCTASK_CANCELLED];

grTask.addQuery('state', 'IN', inQuery);
grTask.addQuery('active', 'false');
grTask.addNotNullQuery('closed_at');
grTask.addQuery('parent.active', 'false');
grTask.orderByDesc('parent.closed_at');
grTask.orderBy('number');
} else {
var inQuery = [hr_Constants.DOCTASK_DRAFT,hr_Constants.DOCTASK_WORK_IN_PROGRESS];

grTask.addQuery('state', 'IN',inQuery);
grTask.addQuery('parent.active', 'true');
grTask.addQuery('active', 'true');
grTask.orderBy('number');
}
grTask.query();
while (grTask.next()) {
var grCaseParent = grTask.parent.getRefRecord();
this._hrCaseParent(grCaseParent, checkCompleted);
}
}

*/
var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addQuery('approver', this._user);
grApproval.addQuery('sysapproval.sys_class_name', 'INSTANCEOF', 'sn_hr_core_case');
if (checkCompleted) {
grApproval.addQuery('state', 'IN', 'approved, rejected,not_required');
grApproval.addQuery('sysapproval.active', 'false');
grApproval.orderByDesc('sysapproval.closed_at');
} else {
grApproval.addQuery('sysapproval.active', 'true');
}
grApproval.query();
while (grApproval.next()) {
var parentRecord = grApproval;
parentRecord = parentRecord.sysapproval.getRefRecord();
this._hrCaseParent(parentRecord, checkCompleted);

}

return this.cases;
},

//consider the case for the input GlideRecord if parent is not already considered. checkCompleted is false for getting open cases and true for closed cases
_hrCaseParent: function(grCase, checkCompleted) {
var parentRecord = grCase;
var addCase = true;
var level = 3;

while (addCase && level >= 1) {
level--;
if (checkCompleted && (parentRecord.getValue('active') == 1) && (parentRecord.getValue('opened_for') == this._user || sn_hr_core.hr_Case.userHasSubjectPersonAccess(parentRecord)))
addCase = false;
else if (parentRecord.getUniqueValue() && parentRecord.isValidRecord() && (hr_caseMyRequestFilterUtil.hrCaseTables.indexOf(parentRecord.getRecordClassName()) >= 0)) { //Exclude the record for which parents are already considered for display
if (this.cases.indexOf(parentRecord.getUniqueValue().toString()) >= 0 && (parentRecord.getValue('opened_for') == this._user || sn_hr_core.hr_Case.userHasSubjectPersonAccess(parentRecord))) // choose not to display case only if its parent already display and is openedFor or Subject Person case
addCase = false;
else
parentRecord = parentRecord.parent.getRefRecord();
} else
break;

}

if (addCase)
this.cases.push(grCase.getUniqueValue().toString());
},

hr_scRequestMyRequestFilter: function(checkCompleted) {
var approvalTable = ['sc_request'];

var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addQuery('approver', this._user);
grApproval.addQuery('sysapproval.sys_class_name', 'IN', approvalTable);
if (checkCompleted) {
grApproval.addQuery('state', 'IN', 'approved, rejected,not_required');
grApproval.addQuery('sysapproval.active', 'false');
grApproval.orderByDesc('sysapproval.closed_at');
} else
grApproval.addQuery('sysapproval.active', 'true');

grApproval.query();
while (grApproval.next()) {
var parentRecord = grApproval;
parentRecord = parentRecord.sysapproval.getRefRecord();

if (parentRecord.getUniqueValue() && parentRecord.isValidRecord()) {
if (this.cases.indexOf(parentRecord.getUniqueValue().toString()) < 0)
this.cases.push(parentRecord.getUniqueValue().toString());
}
}

return this.cases;
},

hr_universalRequestMyRequestFilter: function(checkCompleted) {
var grCase = new GlideRecord('sn_hr_core_case');
grCase.addQuery('hr_service.subject_person_access', true);
grCase.addQuery('subject_person', this._user);
grCase.addEncodedQuery("opened_forNSAMEASsubject_person");
grCase.addQuery('state', '!=', hr_Constants.CASE_DRAFT);
grCase.addNotNullQuery('universal_request');
if (checkCompleted) {
grCase.addQuery('active', 'false');
grCase.addQuery('universal_request.active', 'false');
grCase.addNotNullQuery('closed_at');
} else {
grCase.addActiveQuery();
grCase.addQuery('universal_request.active', 'true');
}
grCase.orderBy('number');
grCase.query();

while (grCase.next()) {
this.cases.push(grCase.getUniqueValue().toString());
}

return this.cases;
},
type: 'hr_caseMyRequestFilterUtil'
};

Hello ,

Do you have any thoughts below community post

https://community.servicenow.com/community?id=community_question&sys_id=968b59c71b5a0910ed6c9979b04bcb07