Request tab on the My active items widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2023 09:57 PM
I'm using the OOB Request tab on 'My Active Items' widget to show the request count and on click of that redirection to my requests page.
A per OOB My requests page is showing the REQ, HR and INC counts, but as per the client requirement ,REQ's are removed, and only RITM's are taken to consideration.
So On the My Active Items widget also how to make the RITM's count visible instead of REQ's count. So that both will be aligned correctly.
If there are 2 RITM's for a REQ, only 1 count is visible now. so how to make such that Requests configuration will take the count as 2 instead of 1.
TIA.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2023 11:57 PM - edited ‎11-14-2023 11:57 PM
Hi @Jack Littlewort - I've created this one, but deactivating 'sc_request' filter, impacting the visibility of RITM's in 'my requests' page.
So I've worked on OOB script include(with no option left behind) - Now the user with 4ritms on REQ, is able to get the count as proper, but still there is an issue like if the user is having 8 records on my requests page. but the count is showing as 9+.
getRequestsCount: function() {
var reqCount = 0;
var ids = [];
var taskGr;
var myReqConfigList = this._getMyRequestQueryInfo();
for (var i = 0; i < myReqConfigList.length && reqCount <= this.ITEM_SUMMARY_COUNT_LIMIT; i++) {
var myReqConfigRecord = myReqConfigList[i];
var reqQuery = this._getMyReqRecQuery(myReqConfigRecord, true);
reqQuery.query();
if (reqQuery.next())
reqCount += Number(reqQuery.getAggregate('COUNT'));
}
gs.info('reqCount is: '+reqCount);
return reqCount;
},
/*
* Gets request filter query details
* @output: returns the dictionary of requests with details.
*/
_getMyRequestQueryInfo: function() {
var myReqConfigList = [];
var rq_filter = new GlideRecord('request_filter');
rq_filter.addActiveQuery();
if (rq_filter.isValidField('applies_to'))
//rq_filter.addQuery('applies_to', 1).addOrCondition('applies_to', 10);
rq_filter.addEncodedQuery('applies_to=1^table=sc_req_item^ORtable=incident^ORtable=sn_hr_core_case');
rq_filter.query();
while (rq_filter.next()) {
var myReqConfigRecord = {};
myReqConfigRecord.table = rq_filter.table_name.toString();
if (rq_filter.isValidField('table')) {
myReqConfigRecord.table = rq_filter.table.toString();
}
myReqConfigRecord.filter = rq_filter.filter.toString();
myReqConfigList.push(myReqConfigRecord);
}
return myReqConfigList;
},
/*
* Gets request filter record's detail
* @output: returns request record's sysids and details.
*/
_getMyReqRecQuery: function(reqConfigRecord, isAggregate) {
var ids = [];
var gr;
var tableName = reqConfigRecord.table;
if (isAggregate) {
gr = new GlideAggregate(tableName);
gr.addAggregate('COUNT');
} else {
gr = new GlideRecord(tableName);
}
gr.addQuery(reqConfigRecord.filter);
gr.addQuery('active', '=', true);
if (isAggregate)
return gr;
gr.query();
while (gr.next()) {
ids.push(gr.sys_id + '');
}
return ids;
},
/*
* Gets the sysid's for all the requests
*/
_getMyRequestSysIds: function() {
var ids = {};
var rq_filter = new GlideRecord('request_filter');
rq_filter.addActiveQuery();
if (rq_filter.isValidField('applies_to'))
rq_filter.addEncodedQuery('applies_to=1^ORapplies_to=10');
rq_filter.query();
while (rq_filter.next()) {
var tableName = rq_filter.table_name;
if (rq_filter.isValidField('table'))
tableName = rq_filter.table;
var gr = new GlideRecord(tableName);
gr.addQuery(rq_filter.filter);
gr.query();
while (gr.next()) {
var portalSettings = {};
portalSettings.page = rq_filter.portal_page.nil() ? '' : rq_filter.portal_page.getDisplayValue() + '';
portalSettings.primary_display = rq_filter.primary_display.nil() ? '' : rq_filter.primary_display + '';
portalSettings.secondary_displays = rq_filter.secondary_display.nil() ? '' : rq_filter.secondary_display + '';
ids[gr.sys_id + ''] = portalSettings;
}
}
return ids;
},
/* Gets the display value for the given field
* @input: glide record
* @input: field name
* @output: display value
*/
getFieldDisplayValue: function(gr, name) {
var id = gr.getUniqueValue();
gr = new GlideRecord(gr.getRecordClassName());
if (gr.get(id))
return gr.getDisplayValue(name);
else
return "";
},
/* Gets the label for the given field
* @input: glide record
* @input: field name
* @output: label
*/
getFieldLabel: function(gr, name) {
gr = new GlideRecord(gr.getRecordClassName());
return gr.getElement(name).getLabel();
},
/*
* Gets the list view data
* @input: glide record for requests
* @input: JSON containing card mapping field labels
* @input: @input: limit, how many records to fetch
* @output JSON cantaining card mapping values
*/
_getRequestListViewData: function(gr, myRequestMap, getlim) {
var ids = [];
var recordIdx = 0;
while (gr.next() && recordIdx < getlim) {
var requestBadgeColor = "#CBE9FC";
var reqConfigRecord = myRequestMap[gr.sys_id];
var portalSettings = {};
var page = reqConfigRecord.page;
var primary_display = reqConfigRecord.primary_display;
var secondary_display = reqConfigRecord.secondary_displays;
if (gr.getRecordClassName() == 'sc_request') {
var ritm = new GlideRecord("sc_req_item");
if (!ritm.isValid())
continue;
ritm.addQuery("request", gr.getUniqueValue());
ritm.query();
if (ritm.getRowCount() == 0)
continue;
if (ritm.getRowCount() > 1)
portalSettings.title = (gs.getMessage("{0} requested items", ritm.getRowCount()));
else {
ritm.next();
portalSettings.title = (ritm.cat_item.getDisplayValue() || ritm.getDisplayValue("short_description"));
}
page = page ? page : 'sc_request';
portalSettings.itemUrl = "?id=" + page + "&table=sc_request&sys_id=" + gr.getUniqueValue();
} else {
portalSettings.title = (primary_display ? this.getFieldDisplayValue(gr, primary_display) : this.getFieldDisplayValue(gr, 'number'));
page = page ? page : 'ticket';
portalSettings.itemUrl = "?id=" + page + "&table=" + gr.getRecordClassName() + "&sys_id=" + gr.getUniqueValue();
}
if (secondary_display) {
var secondaryFields = secondary_display.split(",");
portalSettings.description = secondaryFields[0] ? this.getFieldDisplayValue(gr, secondaryFields[0]) : "";
portalSettings.field1Label = secondaryFields[1] ? this.getFieldLabel(gr, secondaryFields[1]) : "";
portalSettings.field1Value = secondaryFields[1] ? this.getFieldDisplayValue(gr, secondaryFields[1]) : "";
portalSettings.field2Label = secondaryFields[2] ? this.getFieldLabel(gr, secondaryFields[2]) : "";
portalSettings.field2Value = secondaryFields[2] ? this.getFieldDisplayValue(gr, secondaryFields[2]) : "";
} else
portalSettings.description = (this.getFieldDisplayValue(gr, 'short_description'));
portalSettings.badge = this.getFieldDisplayValue(gr, 'state');
portalSettings.badgeTextColor = "#181A1F";
portalSettings.badgeColor = requestBadgeColor;
portalSettings.target = "";
if (this._isValidActivityObject(portalSettings)) {
ids.push(portalSettings);
recordIdx++;
}
}
return ids;
},
/*
* Gets the list view for Requests
* @input: limit, how many records to fetch
*/
getRequestsDatalen: function(limit) {
var myRequestMap = this._getMyRequestSysIds();
var taskIDs = Object.keys(myRequestMap);
var gr = new GlideRecordSecure('task');
gr.addQuery('sys_id', taskIDs);
gr.addActiveQuery();
gr.orderByDesc('sys_updated_on');
gr.query();
data.request = {};
data.request.count = 0;
data.request.req_list = [];
var recordIdx = 0;
var limit = 15;
data.lastLimit = limit;
var getlim = data.lastLimit;
while (recordIdx < getlim && gr.next()) {
var portalSettings = myRequestMap[gr.getUniqueValue()];
var record = {};
if (gr.getRecordClassName() == 'sc_request') {
var ritm = new GlideRecord("sc_req_item");
if (!ritm.isValid())
continue;
ritm.addQuery("request", gr.getUniqueValue()); //Added conditions for RITM
ritm.addActiveQuery();
ritm.query();
if (ritm.getRowCount() == 0)
continue;
for (var k = 0; k < ritm.getRowCount() && recordIdx < getlim && ritm.next(); k++) {
++data.request.count;
recordIdx++;
}
}
}
return this._getRequestListViewData(gr, myRequestMap, getlim);
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2023 05:43 AM
@Janu sree Are we talking about the widget, or the page behind it, as these are two separate things.
Either or, these are configurable options in the platform itself, and don't need changes to the widget or any coding.
To Change the Widget contents itself
Navigate to Employee Center -> Administration -> To-Dos configuration. Here is where you can configure the setup to control what displays in the widget. Don't edit or change the widget at code level, it's a core asset to Employee Center and uses a significant amount of script includes to make it work. There is a reason there is a configuration option for you to use:)
To Change the My Requests page
The My Requests page is actually a HR based page. And the page uses a widget to display what records a user can access. Again, don't go changing or customising any OOTB assets here, you have configuration options
Navigate to My Requests Filter.
Here you can setup what Requests will display on that page through the widget. This is where for example you would make an entry to show the RITMs, instead of the REQ (And where I do this change for customers that ask)