Dynamic Assigned to Visual Task Boards

jwagner
Tera Contributor

ServiceNow Friends,

We have been able to create task boards on an individual basis. We'd like to have a visual task board exist in the application menu and display results dynamically based on "assigned to". We can create the board we need, but don't want to create individually for each user.

Thanks,

Jeremy

1 ACCEPTED SOLUTION

LaurentChicoine
Tera Guru

Hi Jeremy,



This is a nice idea.



Here is how to do it (I made it in Istanbul so not sure about the compatibility with older versions, differences should only be in the creation of the task board):



1. Create a processor that will create the board if the user does not already have a visual task board for his tasks or if the user already has a board then we will redirect him to that board. The board sys_id will be stored as a user preference of the user.



Name: VTBTasksAssignedToMe


Type: script


Path: vtb_tasks_assigned_to_me


Script:


(function process(g_request, g_response, g_processor) {



      var vtbId = gs.getPreference('vtb.assigned.to.me');


      var vtbGr = new GlideRecord('vtb_board');


     


      if(!vtbId || !vtbGr.get(vtbId)){


              vtbGr = new GlideRecord('vtb_board');


              vtbGr.initialize();


              vtbGr.name = gs.getMessage('Tasks assigned to me');


              vtbGr.owner = gs.getUserID();


              vtbGr.table = 'task';


              vtbGr.filter = 'assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe';


              vtbGr.field = '__KANBAN__';


              vtbGr.card_limit = 1000;


              vtbGr.stream_limit = 50;


              vtbGr.show_list_toggle = true;


              vtbGr.background_color = 'vtb-board-color-1';


              vtbId = vtbGr.insert();


             


              //If using field kanban which is the default lanes we must create these lanes


              if(vtbGr.field == '__KANBAN__'){


                      var lanes = [gs.getMessage('To Do'), gs.getMessage('Doing'), gs.getMessage('Done')];


                     


                      lanes.forEach(function(lane, index){


                              var laneGr = new GlideRecord('vtb_lane');


                              laneGr.initialize();


                              laneGr.board = vtbId;


                              laneGr.name = lane;


                              laneGr.order = index;


                              laneGr.insert();


                      });


                     


              }


             


              //Setting the user prefrence


              gs.getUser().setPreference('vtb.assigned.to.me', vtbId);


      }


     


      g_processor.redirect('$vtb.do?sysparm_board=' + vtbId);



})(g_request, g_response, g_processor);



You can customize the script to change the default values. The filter is an encoded query, you might want to modify it, let's say to add "^active=true".



If you have different needs for that type of Visual Task board generated from a menu you might want to make this processor more scalable by adding parameters. I made it quickly to show the functionality.



2. Create a module to make this processor run



Title: Visual Task Board - Assigned to me (you can give another title if you want)


Application Menu: Choose what you want


Link type: URL (from Arguments:)


Arguments: vtb_tasks_assigned_to_me.do


Roles: If you want to limit the use to a specific role (ex: itil)



3. Create ACL for that processor (Only if you chose to limit the use to the specific role)



Type: processor


Name: VTBTasksAssignedToMe


Requires role: Role(s) you selected for the module



I hope this helps you, don't hesitate if you have any question.


View solution in original post

16 REPLIES 16

LaurentChicoine
Tera Guru

Hi Jeremy,



This is a nice idea.



Here is how to do it (I made it in Istanbul so not sure about the compatibility with older versions, differences should only be in the creation of the task board):



1. Create a processor that will create the board if the user does not already have a visual task board for his tasks or if the user already has a board then we will redirect him to that board. The board sys_id will be stored as a user preference of the user.



Name: VTBTasksAssignedToMe


Type: script


Path: vtb_tasks_assigned_to_me


Script:


(function process(g_request, g_response, g_processor) {



      var vtbId = gs.getPreference('vtb.assigned.to.me');


      var vtbGr = new GlideRecord('vtb_board');


     


      if(!vtbId || !vtbGr.get(vtbId)){


              vtbGr = new GlideRecord('vtb_board');


              vtbGr.initialize();


              vtbGr.name = gs.getMessage('Tasks assigned to me');


              vtbGr.owner = gs.getUserID();


              vtbGr.table = 'task';


              vtbGr.filter = 'assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe';


              vtbGr.field = '__KANBAN__';


              vtbGr.card_limit = 1000;


              vtbGr.stream_limit = 50;


              vtbGr.show_list_toggle = true;


              vtbGr.background_color = 'vtb-board-color-1';


              vtbId = vtbGr.insert();


             


              //If using field kanban which is the default lanes we must create these lanes


              if(vtbGr.field == '__KANBAN__'){


                      var lanes = [gs.getMessage('To Do'), gs.getMessage('Doing'), gs.getMessage('Done')];


                     


                      lanes.forEach(function(lane, index){


                              var laneGr = new GlideRecord('vtb_lane');


                              laneGr.initialize();


                              laneGr.board = vtbId;


                              laneGr.name = lane;


                              laneGr.order = index;


                              laneGr.insert();


                      });


                     


              }


             


              //Setting the user prefrence


              gs.getUser().setPreference('vtb.assigned.to.me', vtbId);


      }


     


      g_processor.redirect('$vtb.do?sysparm_board=' + vtbId);



})(g_request, g_response, g_processor);



You can customize the script to change the default values. The filter is an encoded query, you might want to modify it, let's say to add "^active=true".



If you have different needs for that type of Visual Task board generated from a menu you might want to make this processor more scalable by adding parameters. I made it quickly to show the functionality.



2. Create a module to make this processor run



Title: Visual Task Board - Assigned to me (you can give another title if you want)


Application Menu: Choose what you want


Link type: URL (from Arguments:)


Arguments: vtb_tasks_assigned_to_me.do


Roles: If you want to limit the use to a specific role (ex: itil)



3. Create ACL for that processor (Only if you chose to limit the use to the specific role)



Type: processor


Name: VTBTasksAssignedToMe


Requires role: Role(s) you selected for the module



I hope this helps you, don't hesitate if you have any question.


Amazing ingenuity! Works great!


Hi Laurent,



This is brilliant thanks!



I would like to use this so that rather than it being 'assigned to' it is 'Assignment Group (Dynamic based on user)' and for the VTB to 'Show SLA's' by default. Can you please help me achieve this? I've tried changing the script myself but no luck unfortunately.



Any help would be greatly appreciated.  


Hi Nabeel,



I decided to make this processor more scalable, for that kind of need:



New name: DynamicVTB


Path: dynamic_vtb


Script:


(function process(g_request, g_response, g_processor) {




  var AVAILABLE_TYPES = {


  'tasks_assigned_to_me': {


  'name': gs.getMessage('Tasks assigned to me'),


  'table': 'task',


  'preference_name': 'vtb.assigned.to.me',


  'filter': 'assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe',


  'field': '__KANBAN__'


  },


  'tasks_assigned_to_my_groups':{


  'name': gs.getMessage('Tasks assigned to my groups'),


  'table': 'task',


  'preference_name': 'vtb.assigned.to.my.groups',


  'filter': 'assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744',


  'field': '__KANBAN__'


  },


  'tasks_assigned_to_my_groups_by_sla':{


  'name': gs.getMessage('Tasks assigned to my groups by SLA'),


  'table': 'task',


  'preference_name': 'vtb.assigned.to.my.groups.by.sla',


  'filter': 'assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744',


  'field': 'u_custom_sla_field'


  }


  };



  var type = g_request.getParameter('type');



  if(typeof AVAILABLE_TYPES[type] == 'undefined'){


  g_processor.writeOutput(gs.getMessage('Invalid type'));


  return;


  }



  var vtbId = gs.getPreference(AVAILABLE_TYPES[type].preference_name);


  var vtbGr = new GlideRecord('vtb_board');



  if(!vtbId || !vtbGr.get(vtbId)){


  vtbGr = new GlideRecord('vtb_board');


  vtbGr.initialize();


  vtbGr.name = AVAILABLE_TYPES[type].name;


  vtbGr.owner = gs.getUserID();


  vtbGr.table = AVAILABLE_TYPES[type].table;


  vtbGr.filter = AVAILABLE_TYPES[type].filter;


  vtbGr.field = AVAILABLE_TYPES[type].field;


  vtbGr.card_limit = 1000;


  vtbGr.stream_limit = 50;


  vtbGr.show_list_toggle = true;


  vtbGr.background_color = 'vtb-board-color-1';


  vtbId = vtbGr.insert();



  //If using field kanban which is the default lanes we must create these lanes


  if(vtbGr.field == '__KANBAN__'){


  var lanes = [gs.getMessage('To Do'), gs.getMessage('Doing'), gs.getMessage('Done')];



  lanes.forEach(function(lane, index){


  var laneGr = new GlideRecord('vtb_lane');


  laneGr.initialize();


  laneGr.board = vtbId;


  laneGr.name = lane;


  laneGr.order = index;


  laneGr.insert();


  });



  }



  //Setting the user prefrence


  gs.getUser().setPreference(AVAILABLE_TYPES[type].preference_name, vtbId);


  }



  g_processor.redirect('$vtb.do?sysparm_board=' + vtbId);




})(g_request, g_response, g_processor);




With this new processor, the existing module link would become: dynamic_vtb.do?type=tasks_assigned_to_me



For your use case, if you want the lnaes to be the SLA, you would need to create a new custom field on the task table and dynamicly update that field with the current SLA using a Business rule. You won't be able to have dynamic SLA lanes otherwise.



EDIT: I removed the value form the field Parameters as it was causing other processors to fail and was not required for the script to work.