- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2023 05:54 AM
I have a catalog form which contains location variable referenced to location table.
I want to show only unused values of location table in form.
I don't want to show the values used by user table.
How to achieve this????
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2023 07:51 AM - edited ‎11-14-2023 07:51 AM
Hi @Sourabh22
You can write an Script Include , assume 'ExcludeLocation' and a function called 'getExcludedLocations()' and you can write below code in it:
var usrLoc= [];
var usr = new GlideAggregate('sys_user');
usr.addAggregate('COUNT', 'location');
usr.addEncodedQuery("location!=NULL");
usr.groupBy('location');
usr.query();
while(usr.next())
{
usrLoc.push(usr.getValue('location'));
}
var locArr = [];
var loc = new GlideRecord('cmn_location');
loc.addEncodedQuery("sys_idNOT IN"+locArr);
loc.query();
while(loc.next())
{
locArr.push(loc.getUniqueValue());
}
return "sys_idIN"+locArr;
You can now call this Script Include in your Reference Qualifier of Variable using below link:
javascript: new ExcludeLocation().getExcludedLocations();
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2023 11:19 PM - edited ‎11-14-2023 11:19 PM
still showing all values in location field in the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2023 11:25 PM
Do share updated Script.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2023 11:50 PM
Hi @Sourabh22 ,
Can you please try the script which i have shared it working fine for me i have shared screenshots with output.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2023 11:57 PM
Your code will create performance issue as your are GlideRecord whole User table which may have thousands or record without any filter condition or grouping. Also, you userLocations array will have hundreds of Duplicates which will make the EncodedQuery more time consuming and performance issue.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2023 01:25 AM
hi @AnubhavRitolia ,
Yes its my bad yes he can use addQuery method location is not null and remove duplicates from array with below script
if (uniqueArray.indexOf(array[i]) === -1) {
uniqueArray.push(array[i]);
}
Thanks,
Anand