Display number of surveys assigned to a user in the header menu of service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2018 01:18 AM
In the header menu we have 'Approvals' with the number of approvals displayed next to it, and I would like to do the same for surveys.
I have a menu item on the header called 'My Surveys', which is a scripted list. But I'm not sure how to edit the server script code for the 'My Surveys' menu item to show the number of surveys assigned to that user.
I've copied the code for the 'My Approvals' menu item, but don't know what to change the relevant parts to.
Here's what I have so far;
// only show 30 in header menu dropdown
var max = 30;
var t = data;
t.items = [];
t.count = 0;
t.showAlways = true;
var u = gs.getUser().getID();
// use record watchers to tell header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table':'surveys','filter':'approver=' + u + '^state=active'});
var z = new GlideRecord('sysapproval_approver');
z.addQuery("approver", gs.getUserID());
z.addQuery("state", "requested");
z.orderByDesc('sys_updated_on');
//z.setLimit(max);
z.query();
var link = {};
link.title = gs.getMessage('View all surveys');
link.type = 'link';
link.href = '?id=my_surveys';
link.items = [];
t.items.push(link);
while (z.next()) {
var a = {};
var rec = getRecordBeingApproved(z);
if (!rec.isValidRecord()) // nothing being approved - hmmm
continue;
a.short_description = rec.short_description + "";
if (rec.getRecordClassName() == "sc_request") {
var items = new GlideRecord("sc_req_item");
items.addQuery("request", rec.getUniqueValue());
items.query();
if (items.getRowCount() > 1)
a.short_description = items.getRowCount() + " requested items";
else if (items.getRowCount() == 1) {
items.next();
a.short_description = items.getValue("short_description");
}
}
$sp.getRecordValues(a, z, 'sys_id,sys_updated_on');
a.number = rec.getDisplayValue();
a.__table = z.getRecordClassName();
a.type = 'survey';
t.items.push(a);
t.count++;
}
function getRecordBeingApproved(gr) {
if (!gr.sysapproval.nil())
return gr.sysapproval.getRefRecord();
return gr.document_id.getRefRecord();
}
Thanks in advance! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2018 01:35 AM
Hi sarahleighton,
I am currently looking at the same requirement. Did you manage to resolve this?
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 05:41 AM
No sorry, no one came back, and our requirements changed in the meantime.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 06:34 AM
If you are using the Surveys plugin, you can add "My Surveys" to the SP Header Menu widget (Widget Instances) if it isn't there by default. I can't remember if I added this manually or if it was added by default and it's just a URL:
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven