How do I show tasks assigned to me in the task field within Time Cards

JR Guieb
Tera Expert

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'

};

4 REPLIES 4

Mike Allen
Mega Sage

gr.addQuery('assigned_to', gs.getUserID()) should do it.


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'


};


Put it in both "private" methods, the project and the task one.


dillontjd
Giga Contributor

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