- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2016 07:26 PM
Hi all,
Our Pilot users have discovered that when they do not have any active tickets, they cannot go in and see their inactive tickets
After all requests / incidents are closed, the menu item disappears.
Is there a way to make the menu item stay visible, even when there are no active tickets?
The code for the menu item (this is OOB)
var t = data; // shortcut
t.items = [];
t.count = 0;
var u = gs.getUser().getID();
// use record watchers to tell header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table':'service_task','filter':'active=true^opened_by=' + u});
t.record_watchers.push({'table':'incident','filter':'active=true^caller_id=' + u});
t.record_watchers.push({'table':'sc_request','filter':'active=true^requested_for=' + u});
var st = new GlideRecord('service_task');
if (st.isValid()) {
st.addActiveQuery();
st.addQuery('opened_by', gs.getUserID());
st.orderByDesc('sys_updated_on');
st.query();
while (st.next()) {
var a = {};
$sp.getRecordValues(a, st, 'short_description,sys_id,number,sys_updated_on');
if (st.short_description.nil())
a.short_description = "(No description)";
a.__table = st.getTableName();
a.type = 'record';
a.sortOrder = st.sys_updated_on.getGlideObject().getNumericValue();
t.items.push(a);
t.count++;
}
}
var z = new GlideRecord('incident');
z.addActiveQuery();
z.addQuery('caller_id', gs.getUserID());
z.orderByDesc('sys_updated_on');
z.query();
while (z.next()) {
var a = {};
$sp.getRecordValues(a, z, 'short_description,sys_id,number,sys_updated_on');
if (z.short_description.nil())
a.short_description = "(No description)";
a.__table = z.getTableName();
a.type = 'record';
a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
t.items.push(a);
t.count++;
}
var z = new GlideRecord('sc_request');
z.addActiveQuery();
z.addQuery('requested_for', gs.getUserID());
z.orderByDesc('sys_updated_on');
z.query();
while (z.next()) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', z.getUniqueValue());
ritm.query();
if (!ritm.next())
continue;
var a = {};
$sp.getRecordValues(a, z, 'sys_id,number,sys_updated_on');
if (ritm.hasNext())
a.short_description = ritm.getRowCount() + ' requested items';
else
a.short_description = ritm.cat_item.getDisplayValue() || ritm.getDisplayValue("short_description");
a.__table = z.getTableName();
a.type = 'request';
a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
t.items.push(a);
t.count++;
}
t.items.sort(function(a, b) {
return b.sortOrder - a.sortOrder;
});
var link = {};
link.title = gs.getMessage('View all requests');
link.type = 'link';
link.href = '?id=requests';
link.items = [];
t.items.unshift(link); // put this first
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2016 12:43 AM
item.showAlways should probably be item.scriptedItems.showAlways
When you declare property in a javascript object, it will be created. You don't have to worry about the property already existing.
If you want to be sure that the property actually exist you could do a console.log("MY DEBUG: " + item.scriptedItems.showAlways);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2017 04:43 AM
Figured it out, I had to configure the template to count <= 0 too, same as the client controller...
Also remember to like your custom header menu widget to the top SP Header Menu widget.
Template:
<a ng-if="item.items.length == 0 && !item.scriptedItems" ng-href="{{item.href}}">{{ item.label }}</a>
<a ng-if="item.items.length > 0" href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ item.label }} <span class="caret"></span></a>
<ul ng-if="item.items.length > 0" class="dropdown-menu" role="menu">
<li ng-repeat="item in item.items" ng-include="'menuTemplate'" />
</ul>
<!-- "item.scriptedItems.showAlways" allows the menu item to show, set: "data.showAlways = true;" in the menu item's server script -->
<a ng-if="item.scriptedItems.count >= 0 || item.scriptedItems.showAlways" href="javascript:void(0)" data-toggle="dropdown" title="{{item.hint}}">
<span ng-bind-html="item.label"></span>
<span ng-if="!item.scriptedItems.omitBadge" class="label label-as-badge label-primary sp-navbar-badge-count">{{item.scriptedItems.count}}</span>
</a>
<sp-dropdown-tree ng-if="item.scriptedItems.count >= 0 ||bitem.scriptedItems.showAlways" items="item.scriptedItems.items" />
Thanks Chandra.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2017 04:56 AM
Actually, by changing both places in the template made the approvals link also always show, even if showAlways was = false for that menu item.
It is only the last if statement in the template which should be changed to <=, like this:
---------------
------
<a ng-if="item.scriptedItems.count > 0 || item.scriptedItems.showAlways" href="javascript:void(0)" data-toggle="dropdown" title="{{item.hint}}">
------------
----
-----------
<sp-dropdown-tree ng-if="item.scriptedItems.count >= 0 ||bitem.scriptedItems.showAlways" items="item.scriptedItems.items" />
Now it works as intended, controlled by the showAlways variable in the individual menu item scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2017 05:01 AM
Oh snap, sorry guys for all the posts, Chandra corrected me..
you dont need to modify that last line in the template either, my issue was that it said: bitem.scriptedItems.showAlways instead of item.scriptedItems.showAlways.
It works fine as is actually...
Sorry!
<sp-dropdown-tree ng-if="item.scriptedItems.count > 0 ||bitem.scriptedItems.showAlways" items="item.scriptedItems.items" />
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2017 05:19 AM
Also note this: Re: Cloning the Header Menu Widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2018 05:28 AM