Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

@Chaitanya ILCR I tired removing the dot (.) and new keyword but it still does not work 

nupur_goswami_0-1747914312010.png


@Ankur Bawiskar Also giving the correct sys ID of the catalog item does not work 

nupur_goswami_1-1747914552295.png

 

 

@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

@nupur_goswami 

did you try running the script in background and see if it gave array of REQ sysIds?

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'));
}
gs.info(arr.toString());

AnkurBawiskar_0-1747915068333.png

 

 

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

nupur_goswami
Tera Contributor

@Ankur Bawiskar 

using: instead of that colon word worked

Thank you so much 

I have marked the solution as helpful 

@nupur_goswami 

Glad to help.

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