- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2022 05:28 AM
Hi all!
I need help with this. I have a territory field on a form, and depending the selected territory, I need to filter a Reference field that has the user table. The users from that territory only have to show. I guess I'll have to use a Client script. Any idea on how I can do this?
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2022 05:31 PM
I prepared two fields.
WBS Territory is a Choice fields with two choices.
As I think company is a reference field, Script Include should return the sys_id of the company record. You should compare not a Label but a Value of choices.
var TerritoryUserUtils = Class.create();
TerritoryUserUtils.prototype = {
initialize: function() {
},
getCompany: function(territory) {
var grCompany = new GlideRecord("core_company");
if (territory == 'us')
grCompany.addQuery('name', 'ACME North America');
else if (territory == 'jp')
grCompany.addQuery('name', 'ACME Japan');
grCompany.query();
if (grCompany.next())
return grCompany.sys_id;
},
type: 'TerritoryUserUtils'
};
And then, I call it from advanced ref qual of User fields. (Please rename the variables to suit your environment)
If your Territory isn't "Dropdown with --None--", if clause might not be needed.
javascript:if (current.u_wbs_territory != '') "company=" + new TerritoryUserUtils().getCompany(current.u_wbs_territory);
Finally it seems to be working fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2022 05:58 AM
Why don't you use advanced reference qualifier?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2022 06:07 AM
Hello! The problem is I have a list of territories on the field, and they're not written the same as the territories of the user table. For example, on the territory field on the form an option is "US" and on the user table it shows as "United States of America". Hope I explained it clear.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2022 07:31 AM
Hi.
If I were you, I use Script Include.
And call it from reference field of user with advanced reference qualifier.
You can also use GlideRecord in Script Include, so you can create "Alias" field in the Territory table, and get a list of users that match your search result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2022 09:54 AM
Hello, it is not working right now, let me show you, I think it's a naming problem:
Script include:
(The blue part is the name of the company)
On the first part, the 'Company' field is where the location info is located on that table. And the second part, I put the name of the variable where the user is selecting the territory (for ex 'US'). Hope I explained correctly and you can give me a hand with this 🙂