How do I show tasks assigned to me in the task field within Time Cards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2017 11:22 AM
I know there is a Reference Qualifier that is using the TimeCardQueryHelper script include to filter out project tasks and tasks depending on which category is selected "Project/Project Task or Task Work"
I changed the reference qualifier to Simple and built conditions for Assigned to is Dynamic (me) and that almost works. The only issue with that is it will show all tasks (projects, project tasks, incident, change, problem, etc) no matter what category is selected.
My problem and requirement is how to modify that script to only show tasks or project/project tasks assigned to the person searching for a task within the correct category?
Here is the OOB script used in the "TimeCardQueryHelper" script include:
var TimeCardQueryHelper = Class.create();
TimeCardQueryHelper.prototype = {
initialize: function(gr) {
this.gr = gr;
},
getTaskFilter: function() {
if (this.gr.category == 'project_work')
return this._projectAndProjectTasksQuery();
else if (this.gr.category == 'task_work')
return this._allTasksQuery();
},
_projectAndProjectTasksQuery: function() {
var gr = new GlideRecord('task');
var qc = gr.addQuery('sys_class_name', 'INSTANCEOF', 'pm_project');
qc.addOrCondition('sys_class_name', 'INSTANCEOF', 'pm_project_task');
gr.addQuery('sys_class_name', '!=', 'pm_project_task_link');
return gr.getEncodedQuery();
},
_allTasksQuery: function() {
var gr = new GlideRecord('task');
gr.addQuery('sys_class_name', 'INSTANCEOF', 'task');
return gr.getEncodedQuery();
},
type: 'TimeCardQueryHelper'
};
- Labels:
-
Project Portfolio Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2017 11:49 AM
gr.addQuery('assigned_to', gs.getUserID()) should do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2017 01:20 PM
I placed gr.addQuery('assigned_to', gs.getUserID()) as shown below in bold but now it is showing all tasks assigned to me or not in any category. I must be placing it in the wrong place.
var TimeCardQueryHelper = Class.create();
TimeCardQueryHelper.prototype = {
initialize: function(gr) {
this.gr = gr;
},
getTaskFilter: function() {
if (this.gr.category == 'project_work')
return this._projectAndProjectTasksQuery();
else if (this.gr.category == 'task_work')
return this._allTasksQuery();
},
_projectAndProjectTasksQuery: function() {
var gr = new GlideRecord('task');
var qc = gr.addQuery('sys_class_name', 'INSTANCEOF', 'pm_project');
qc.addOrCondition('sys_class_name', 'INSTANCEOF', 'pm_project_task');
gr.addQuery('assigned_to', gs.getUserID());
gr.addQuery('sys_class_name', '!=', 'pm_project_task_link');
return gr.getEncodedQuery();
},
_allTasksQuery: function() {
var gr = new GlideRecord('task');
gr.addQuery('sys_class_name', 'INSTANCEOF', 'task');
return gr.getEncodedQuery();
},
type: 'TimeCardQueryHelper'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2017 02:08 PM
Put it in both "private" methods, the project and the task one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2019 06:09 AM
Hi JR Guib, did this work for you? I have a similar requirement and I have tried what Mike suggested below, however I am still showing all task. Please help if you can.
Thanks
Tina