Skip to main content

Group tasks widget in Service Portal

 



widget takes you back into classic UI view when the task number is clicked. Lists all ticket types assigned to the group the logged in user belongs to

script - HTML

<div class="panel panel-default"> <div class="panel-heading clearfix"> <div class="pull-right"> <a class="btn btn-default btn-sm" ng-click="showFilters = !showFilters"><i class="fa fa-filter"></i></a> </div> <div class="panel-title">My Groups Tasks</div> </div> <div class="panel-body" ng-show="showFilters"> <form class="form-inline"> <div class="form-group"> <label for="textSearch">Search</label> <input id="textSearch" class="form-control" type="text" ng-model="textSearch" placeholder="Search... "/> </div> <div class="form-group"> <label for="taskType">Task type</label> <select id="taskType" class="form-control" ng-model="table"> <option value="">All</option> <option ng-repeat="table in tables" value="{{table}}">{{table}}</option> </select> </div> <div class="form-group"> <label for="assignment">Assignment</label> <select id="assignment" class="form-control" ng-model="assigned"> <option value="">All</option> <option value="true">Unassigned</option> </select> </div> </form> </div> <table class="table table-striped"> <thead> <tr> <th class="col-xs-6" ng-click="sortBy('number')"> Task <span class="sortorder" ng-show="propertyName === 'number'" ng-class="{reverse: reverse}"></span> </th> <!--<th class="col-xs-2">Number</th> <th class="col-xs-4">Short description</th>--> <th class="col-xs-2" ng-click="sortBy('state')"> State <span class="sortorder" ng-show="propertyName === 'state'" ng-class="{reverse: reverse}"></span> </th> <th class="col-xs-2" ng-click="sortBy('assignment_group')"> Assignment group <span class="sortorder" ng-show="propertyName === 'assignment_group'" ng-class="{reverse: reverse}"></span> </th> <th class="col-xs-2" ng-click="sortBy('assigned_to')"> Assigned to <span class="sortorder" ng-show="propertyName === 'assigned_to'" ng-class="{reverse: reverse}"></span> </th> </tr> </thead> <tbody> <tr ng-repeat="task in tasks | orderBy:propertyName:reverse | filter: {$:textSearch,unassigned:assigned,tableName:table}"> <!--<td class="col-xs-2">{{task.number}}</td> <td class="col-xs-4">{{task.short_description}}</td>--> <td class="col-xs-6"> <p class=""><a href="/nav_to.do?uri={{task.table}}.do?sys_id={{task.sys_id}}">{{task.short_description}}</a></p> <span>{{task.number}}</span> </td> <td class="col-xs-2">{{task.state}}</td> <td class="col-xs-2">{{task.assignment_group}}</td> <td class="col-xs-2">{{task.assigned_to}}</td> </tr> </tbody> </table> </div>

script: CSS

.sortorder:after { content: '\25b2'; // BLACK UP-POINTING TRIANGLE } .sortorder.reverse:after { content: '\25bc'; // BLACK DOWN-POINTING TRIANGLE } .form-group{margin-right:1em;}

script: client script

function($scope) { var c = this; $scope.tables = c.data.tables; $scope.tasks = c.data.tasks; $scope.propertyName = 'number'; $scope.reverse = true; $scope.showFilters = true; $scope.sortBy = function(propertyName) { $scope.reverse = ($scope.propertyName === propertyName) ? !$scope.reverse : false; $scope.propertyName = propertyName; }; }

script: option schema

[{"name":"title","section":"Presentation","default_value":"My Requests","label":"Title","type":"string"},{"name":"show_view","section":"Behavior","default_value":"true","label":"Show View","type":"boolean"},{"hint":"Number of items per page","name":"items_per_page","section":"Behavior","default_value":"15","label":"Items per page","type":"integer"}]

script: server script



(function() { data.tasks = []; var tableList = []; var gr = new GlideRecord("task"); gr.addActiveQuery(); gr.addEncodedQuery("assignment_group=javascript:getMyGroups()"); gr.addQuery("sys_class_name", "!=", "sc_request"); gr.query(); while(gr.next()){ tableList.push(gr.getClassDisplayValue()); var object = {}; object.table = gr.getValue("sys_class_name"); object.tableName = gr.getClassDisplayValue(); object.sys_id = gr.getUniqueValue(); object.number = gr.getDisplayValue("number"); object.short_description = gr.getDisplayValue("short_description"); object.state = gr.getDisplayValue("state"); object.assignment_group = gr.getDisplayValue("assignment_group"); object.assigned_to = gr.getDisplayValue("assigned_to"); object.unassigned = ''; if(gr.getDisplayValue("assigned_to") == '') object.unassigned = true; data.tasks.push(object); } data.tables = new ArrayUtil().unique(tableList); })();







Comments

Popular posts from this blog

ServiceNow check for null or nil or empty (or not)

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g.  var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord  addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ())  option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){

Service Catalog: variable advanced reference qualifiers

Call a script include to apply a reference qualifier on a catalog item variable: - variable reference qualifier dependent on another variable selection, in this case a variable referencing sys_user (requested_for) On the catalog item form. variable name to apply ref qual filter : retail_equipment variable reference qualifier (on cmdb table ): javascript : new  refqual_functions (). lostStolen_getAssignedCIs (); client-callable script include ( refqual_functions)  function : lostStolen_getAssignedCIs : function (){         //--called from variable set client script, for lost/stolen request (service catalog)     gs . log ( current . variables . requested_for , 'retail_lostStolen_getAssignedCIs' );         return ( 'install_statusNOT IN8,7^owned_by=' + current . variables . requested_for );             //owned_by=1269b79937f1060041c5616043990e41^install_statusNOT IN8,7            },