Filter the reference field data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 12:36 PM
Hello,
I need to filter the data in the reference field. In the Purchase request, I'm displaying the reference field called "Quote request." If the user has the ITIL role, I want to display all quote request numbers. If the user doesn't have the ITIL role, show the quote request number opened by the user or if the user is the requestor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 01:03 PM - edited 05-21-2024 12:36 PM
Hi @Reddy
You can do it by creating a script include and call it as a reference qualifier(advance)
Script Include:
var purchaseUtils = Class.create();
purchaseUtils.prototype = {
initialize: function() {
},
getRequest: function() {
var currentUserID = gs.getUserID();
var currentUser = new GlideRecord('sys_user');
if (currentUser.get(currentUserID)) {
if (currentUser.hasRole('itil')) {
gs.log("Returning empty because of itil role");
return ''; // means not giving any filter
} else {
gs.log("Returning query values");
return 'opened_by=' + currentUserID;
}
},
type: 'purchaseUtils'
};
Reference qualifer
javascript: new purchaseUtils().getRequest();
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 11:19 AM
@SAI VENKATESH script is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 12:37 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 01:27 AM
Hi @Reddy ,
I have tried for requested item table , please correct the table name according to your requirement,
var getRequestedItem = Class.create();
getRequestedItem.prototype = {
initialize: function() {},
getRequestedFor: function() {
var userId = gs.getUserID();
var hasItil = gs.getUser().hasRole("itil");
var arr = [];
var gr = new GlideRecord('sc_req_item'); //change the table name
if (hasItil == false || hasItil == 'false') {
gr.addEncodedQuery('opened_by=' + userId);
}
gr.query();
while (gr.next()) {
arr.push(gr.sys_id.toString());
}
return "sys_idIN"+arr.toString();
},
type: 'getRequestedItem'
};
Reference qualifier:
javascript: new getRequestedItem().getRequestedFor();
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang