Create a filter of user table depending on selected field form

Magali Legaspi
Tera Contributor

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!

1 ACCEPTED SOLUTION

Community Alums
Not applicable

I prepared two fields.

Fields.PNG


WBS Territory is a Choice fields with two choices.

WBS Territory.PNG


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);​

User Advanced Ref Qual.PNG

Finally it seems to be working fine.

result.PNG

 

 

View solution in original post

9 REPLIES 9

Community Alums
Not applicable

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.

Community Alums
Not applicable

Hi.
If I were you, I use Script Include.
スクリーンショット 2022-12-27 0.23.07.png

And call it from reference field of user with advanced reference qualifier.
スクリーンショット 2022-12-27 0.24.02.png


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.

Hello, it is not working right now, let me show you, I think it's a naming problem:

 

Script include:

MagaliLegaspi_0-1672077087928.png

(The blue part is the name of the company)

 

MagaliLegaspi_1-1672077191889.png

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 🙂