- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 12:40 AM
Hello Everyone,
I have a custom table and in there there is a reference field 'REQ Number' available which references sc_request_list. Client requirement is when user click on the search option available on the reference field it should only pull up results - requests is raised from a particular catalog item only. Also user should not be able to see the results only the REQ which are raised by him/her. Hence I tried using Script Include called on Reference Qualifier but still it does not work. Attaching the screenshots from the custom table, Script Include that I created and calling that Script Include from Reference Qualifier.
Any suggestion will be highly appreciated.
Thank you in advance.
Code written on script include
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 04:54 AM
please use : instead of that colon word
javascript: var query; var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addQuery("cat_item.sys_id", "catItemSysId");
gr.query();
while (gr.next()) {
arr.push(gr.getValue('request'));
}
query = 'sys_idIN' + arr.toString();
query;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 12:56 AM
simply use this in the advanced ref qualifier
javascript: var query; var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addQuery("cat_item", "catItemSysId");
gr.query();
while (gr.next()) {
arr.push(gr.getValue('request'));
}
query = 'sys_idIN' + arr.toString();
query;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 02:20 AM
Hi @Ankur
I tried the above script in advanced reference qualifier, but it still does not work. It returns all the records from the sc_request_list table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 02:41 AM
If you give the correct catalog item sysId then it should work fine
try this once
javascript: var query; var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addQuery("cat_item.sys_id", "catItemSysId");
gr.query();
while (gr.next()) {
arr.push(gr.getValue('request'));
}
query = 'sys_idIN' + arr.toString();
query;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 02:30 AM - edited 05-22-2025 02:52 AM
Hi @nupur_goswami ,
looks like there is dot added in the ref qual
remove it an check
and I don't think you need new KEYWORD as well
Script include
var SapEfsApprovalHierachy = Class.create();
SapEfsApprovalHierachy.getFilteredRequests = function(catItemSysId) {
var requestIds = [];
var reqItemGR = new GlideRecord('sc_req_item');
reqItemGR.addQuery('cat_item', catItemSysId);
reqItemGR.query();
while (reqItemGR.next()) {
var request = reqItemGR.request;
if (request.opened_by == gs.getUserID() && request.active) {
requestIds.push(request.sys_id);
}
}
return 'sys_idIN' + requestIds.join();
};
reference qual
javascript:SapEfsApprovalHierachy.getFilteredRequests('Paste your cat item sysid');
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya