Script Include on Reference Qualifier not working

nupur_goswami
Tera Contributor

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.

 

 

nupur_goswami_0-1747899519644.pngnupur_goswami_1-1747899556539.pngnupur_goswami_2-1747899606726.png

 

Code written on script include 

 

var SapEfsApprovalHierachy = Class.create();
SapEfsApprovalHierachy.getFilteredRequests = function(catItemSysId) {
    var userId = gs.getUserID();
    var requestIds = [];
    var id= this.getParameter(catItemSysId);
    var reqItemGR = new GlideRecord('sc_req_item');
    reqItemGR.addQuery('cat_item', id);
    reqItemGR.query();
    while (reqItemGR.next()) {
        var request = reqItemGR.request.getRefRecord();

        if (request.opened_by == userId && request.active == true) {
            requestIds.push(request.sys_id);
        }
    }

    if (requestIds.length > 0) {
        return 'sys_idIN' + requestIds.join(',');
    } else {
        return 'sys_id=none';
    }
};

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

@nupur_goswami 

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.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@nupur_goswami 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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. 

nupur_goswami_0-1747905623915.png

 

@nupur_goswami 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Chaitanya ILCR
Kilo Patron

Hi @nupur_goswami ,

 

ChaitanyaILCR_0-1747906216761.png

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