Scripted List on SP Header Menu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2020 12:03 PM
I am trying to create a button on the Service Portal Header Menu that will display contract records (ast_contract) opened by the logged in user. I am having problems filtering the records using the value form u_requested for. I also cannot get the field value from u_vendor_name to appear in the displayed list. I started with adding the following code to the out of the box Angular ng-template spDropdownTreeTemplate.
<!-- Start Contracts Update -->
<a ng-if="mi.type == 'contract'" title="{{mi.short_description}}" href="?id=idea_form&table={{mi.__table}}&sys_id={{mi.sys_id}}">
<span>{{mi.short_description | characters:60}}</span>
<span class="block color-primary text-muted">
<span class="block" style="float: right">
<sn-time-ago timestamp="mi.sys_updated_on" />
</span>
{{mi.number}}
</span>
</a>
<!-- End Contracts Update -->
I created a Scripted List Menu Item for Contracts with the Server Script below
// maximum number of entries in this Menu
var max = 30;
var t = data; // shortcut
t.items = [];
var u = gs.getUser().getID();
// use record watchers to tell header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table':'ast_contract','filter':'active=true^submitter=' + u});
//t.record_watchers.push({'table':'ast_contract','filter':'active=true'});
var z = new GlideRecord('ast_contract');
z.addActiveQuery();
z.addQuery('active', '=','true');
z.addQuery('submitter', gs.getUserID());
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();
while (z.next()) {
var a = {};
$sp.getRecordValues(a, z, 'u_vendor_name,sys_id,number,sys_updated_on');
if (z.u_vendor_name.nil())
a.u_vendor_name = "(No Vendor Name)";
a.__table = z.getTableName();
a.type = 'contract';
a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
t.items.push(a);
}
var z = new GlideRecord('ast_contract');
z.addActiveQuery();
z.addQuery('active', '=','true');
z.addQuery('u_contact_name', gs.getUserID());
z.addQuery('submitter','!=', gs.getUserID());
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();
while (z.next()) {
var a = {};
$sp.getRecordValues(a, z, 'u_vendor_name,sys_id,number,sys_updated_on');
if (z.u_vendor_name.nil())
a.u_vendor_name = "(No Vendor Name)";
a.__table = z.getTableName();
a.type = 'contract';
a.sortOrder = z.sys_updated_on.getGlideObject().getNumericValue();
t.items.push(a);
}
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;
//var link = {title: gs.getMessage('View all contracts'), type: 'link', href: '?id=requests', items: []};
//t.items.unshift(link); // put 'View all requests' first
The new Contracts button should be similar to the out of the box Ideas button where the filter is applied and field values are displayed with the record.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2021 09:36 AM
THANK YOU!!!!!!!
Susan Williams, Lexmark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2020 10:45 PM
Hi ,
Found any solution? I am also facing same issue.