Skip to main content

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

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            },

Get URL Parameter - server side script (portal or classic UI)

Classic UI : var sURL_editparam = gs . action . getGlideURI (). getMap (). get ( ' sysparm_aparameter ' ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); } Portal : var sURL_editparam = $sp . getParameter ( " sysparm_aparameter " ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); }