ServiceNow how to code a top menu 'my tickets' item


Angular ng-template   spDropdownTreeTemplate    sp_ng_template_492127b05b301200e39fc7ad31f91a50   
Menu Item                   My Tickets                            sp_rectangle_menu_item_b8cee8de1b6c5110737aa6c8bd4bcbd3

 

angular template (sp_ng_template):

 

<a ng-if="mi.type == 'link'" title="{{::mi.title}}" target="{{::mi.target}}" ng-href="{{::mi.href}}" ng-click="collapse()" role="menuitem"> {{::mi.title | characters:60}} <span ng-if="::!item.scriptedItems.omitBadge" class="label label-as-badge label-primary sp-navbar-badge-count">{{::mi.count}}</span> </a> <a ng-if="mi.type == 'record' && !mi.__page" aria-label="${Open} {{::mi.number}} : {{::mi.short_description}}" aria-describedby="id_{{::mi.unique_number}}" ng-href="?id=ticket&table={{::mi.__table}}&sys_id={{::mi.sys_id}}" ng-click="collapse()" role="menuitem"> <span>{{::mi.short_description | characters:60}}</span> <span class="block color-primary text-muted"> <span class="block" style="float: right" id="id_{{::mi.unique_number}}"> <sn-time-ago timestamp="::mi.sys_updated_on" /> </span> {{mi.number}} </span> </a> <a ng-if="mi.type == 'record' && mi.__page" aria-label="${Open} {{::mi.number}} : {{::mi.short_description}}" aria-describedby="id_{{::mi.unique_number}}" ng-href="?id={{::mi.__page}}&table={{::mi.__table}}&sys_id={{::mi.sys_id}}" ng-click="collapse()" role="menuitem"> <span>{{::mi.short_description | characters:60}}</span> <span class="block color-primary text-muted"> <span class="block" style="float: right" id="id_{{::mi.unique_number}}"> <sn-time-ago timestamp="::mi.sys_updated_on" /> </span> {{::mi.number}} </span> </a> <a ng-if="mi.type == 'request'" aria-label="${Open} {{::mi.number}} : {{::mi.short_description}}" aria-describedby="id_{{::mi.unique_number}}" ng-href="?id=sc_request&table={{::mi.__table}}&sys_id={{::mi.sys_id}}" ng-click="collapse()" role="menuitem"> <span>{{::mi.short_description | characters:60}}</span> <span class="block color-primary text-muted"> <span class="block" style="float: right" id="id_{{::mi.unique_number}}"> <sn-time-ago timestamp="::mi.sys_updated_on" /> </span> {{::mi.number}} </span> </a> <a ng-if="mi.type == 'approval'" aria-label="${Open} {{::mi.number}} : {{::mi.short_description}}" aria-describedby="id_{{::mi.unique_number}}" ng-href="?id=approval&table={{::mi.__table}}&sys_id={{::mi.sys_id}}" ng-click="collapse()" role="menuitem"> <span ng-if="mi.short_description">{{::mi.short_description | characters:60}}</span> <span class="block color-primary text-muted"> <span class="block" style="float: right" id="id_{{::mi.unique_number}}"> <sn-time-ago timestamp="::mi.sys_updated_on" /> </span> {{::mi.number}} </span> </a> <a ng-if="mi.type == 'kb'" aria-label="${Open} {{::mi.number}} : {{::mi.short_description}}" aria-describedby="id_{{::mi.unique_number}}" ng-href="?id=kb_article&sys_id={{::mi.sys_id}}" ng-click="collapse()" role="menuitem"> <span ng-if="mi.short_description">{{::mi.short_description | characters:60}}</span> <span class="block color-primary text-muted"> <span class="block" style="float: right" id="id_{{::mi.unique_number}}"> <sn-time-ago timestamp="::mi.sys_updated_on" /> </span> {{::mi.number}} </span> </a> <a ng-if="mi.type == 'cat_item'" aria-label="${Open} {{::mi.short_description}}" aria-describedby="id_{{::mi.unique_number}}" ng-href="?id=sc_cat_item&sys_id={{::mi.sys_id}}" ng-click="collapse()" role="menuitem"> <span ng-if="mi.short_description">{{::mi.short_description | characters:60}}</span> <span class="block color-primary text-muted"> <span class="block" style="float: right" id="id_{{::mi.unique_number}}"> <sn-time-ago timestamp="::mi.sys_updated_on" /> </span> {{::mi.number}} </span> </a> <a ng-if="mi.type == 'guide'" aria-label="${Open} {{::mi.short_description}}" aria-describedby="id_{{::mi.unique_number}}" ng-href="?id=sc_cat_item_guide&sys_id={{::mi.sys_id}}" ng-click="collapse()" role="menuitem"> <span ng-if="mi.short_description">{{::mi.short_description | characters:60}}</span> <span class="block color-primary text-muted"> <span class="block" style="float: right" id="id_{{::mi.unique_number}}"> <sn-time-ago timestamp="::mi.sys_updated_on" /> </span> {{::mi.number}} </span> </a> <a ng-if="mi.type == 'menu' && mi.items.length" aria-label="{{::mi.title}}" ng-click="collapse()" class="menu_trigger right-caret" role="menuitem"> {{::mi.title | characters:60}} </a> <sp-dropdown-tree ng-if="mi.type == 'menu' && mi.items.length" items="mi.items" />



 

menu item (sp_rectangle_menu_item):

 


// maximum number of entries in this Menu var max = 30; var t = data; // shortcut t.items = []; var user = gs.getUser().getID(); var open_inc_filter = 'state!=7^caller_idDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORu_logged_on_behalfDYNAMIC90d1921e5f510100a9ad2572f2b477fe'; var closed_inc_filter = 'state=7^caller_idDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORopened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORu_logged_on_behalfDYNAMIC90d1921e5f510100a9ad2572f2b477fe'; var open_req_filter = 'active=true^opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORu_requested_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORrequested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe'; var closed_req_filter = 'active=false^opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORu_requested_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORrequested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe'; var open_demand_filter = 'active=true^opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORcollaboratorsDYNAMIC90d1921e5f510100a9ad2572f2b477fe'; var closed_demand_filter = 'active=false^opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORcollaboratorsDYNAMIC90d1921e5f510100a9ad2572f2b477fe'; var open_case_filter = 'stateNOT IN3,7^opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORassigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe'; var closed_case_filter = 'stateIN3,7^opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORassigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe'; var target_record_view = '&target_page_id=ticket'/* This esnures users only see the ticket view on portal, which only shows limited fields. */; // use record watchers to tell header when to update dropdown counts t.record_watchers = []; t.record_watchers.push({'table':'incident','filter':open_inc_filter}); t.record_watchers.push({'table':'incident','filter':closed_inc_filter}); /*a.type = 'record'; a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue(); t.items.push(a);*/ var open_inc = { 'title' : gs.getMessage('Open Incidents'), 'url' : '?spa=1&table=incident&id=list&filter='+ open_inc_filter +'&p=1&o=sys_updated_on&d=desc' + target_record_view, 'count' : getRowCount('incident', open_inc_filter) }; var closed_inc = { 'title' : gs.getMessage('Closed Incidents'), 'url' : '?spa=1&table=incident&id=list&filter='+ closed_inc_filter +'&p=1&o=sys_updated_on&d=desc' + target_record_view, 'count' : getRowCount('incident', closed_inc_filter) }; var active_req = { 'title' : gs.getMessage('Active Requests'), 'url' : '?spa=1&table=sc_request&id=list&filter='+ open_req_filter +'&p=1&o=sys_updated_on&d=desc' + target_record_view, 'count' : getRowCount('sc_request', open_req_filter) }; var closed_req = { 'title' : gs.getMessage('Closed Requests'), 'url' : '?spa=1&table=sc_request&id=list&filter='+ closed_req_filter +'&p=1&o=sys_updated_on&d=desc' + target_record_view, 'count' : getRowCount('sc_request', closed_req_filter) }; t.items.push({title: open_inc.title, type: 'link', href: open_inc.url, items: [], count: open_inc.count}); t.items.push({title: closed_inc.title, type: 'link', href: closed_inc.url, items: [], count: closed_inc.count}); t.items.push({title: active_req.title, type: 'link', href: active_req.url, items: [], count: active_req.count}); t.items.push({title: closed_req.title, type: 'link', href: closed_req.url, items: [], count: closed_req.count}); t.items.sort(function(a, b) { return b.sortOrder - a.sortOrder; }); t.items = t.items.slice(0, max); // only want first 30 // t.count = t.items.length; t.count = open_inc.count + active_req.count; var link = {title: gs.getMessage('View all requests'), type: 'link', href: '?id=requests', items: []}; t.items.unshift(link); // put 'View all requests' first function getRowCount(table, filter) { var rec = new GlideRecord(table); rec.addEncodedQuery(filter); rec.query(); return rec.getRowCount(); }

Comments

Popular posts from this blog

GlideRecord setValue

URL link in addInfoMessage