How to write a reference qualifier for a Catalog Item variable?

Chaithra Srini1
Mega Expert

Hi Everyone,

I have a use case to display list of Locations in the Locations reference list based on the requested for company. I have written a script include and called it in an advanced qualifier as below, but it seems to be not working. Could anyone please provide any insights on why? 

Thank you in advance.

Below are the screenshots

find_real_file.png

 

function myScriptInclude() {
var site = ' ';
var b = gs.getUser(); //Logged-in user

var loc = new GlideRecord('cmn_location');
loc.addQuery('company',b.getCompanyID());
loc.query();

while(loc.next()) {
if (site.length > 0) {
//build a comma separated string of groups if there is more than one
site += (',' + loc.company);
}
else {
site = loc.company;
}
}
// return Groups where assigned to is in those groups we use IN for lists
return 'sys_idIN' + site;
}

 

1 ACCEPTED SOLUTION

Hi Chaithra,

the reference variable is referring to cmn_location; but the array is storing the sys_ids of the company table

you need to push sys_id of the cmn_location table i.e.

loc.sys_id.toString()

Actually there is no need of script include you can do this in advanced reference qualifier:

javascript: 'company=' + gs.getUser().getCompanyID()

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

7 REPLIES 7

Swadesh Saraf2
Kilo Guru

javascript:new <scriptIncludeName>().<scriptIncludeFunction>()

 

You will need to call script include like this.

Prateek kumar
Mega Sage

I would do this:

javascript: new myScriptInclude().getLocations()

var myScriptInclude = Class.create();
myScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getLocations: function() {
        var site = [];
        var b = gs.getUser(); //Logged-in user

        var loc = new GlideRecord('cmn_location');
        loc.addQuery('company', b.getCompanyID());
        loc.query();

        while (loc.next()) {
           site.push(loc.company.toString());
            } 
		
   
        // return Groups where assigned to is in those groups we use IN for lists
        return 'sys_idIN' + site;
    },

    type: 'myScriptInclude'
});

find_real_file.png


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Thanks for your response Prateek.

I tried above method and it didn't fetch any Locations. Guess something is missing. 

find_real_file.png

Chaithra Srini1
Mega Expert

Hi all,

I am missing something here, couldn't fetch location records. Something isn't working while returning values. Could someone help me please?

Regards,

Chaithra