How to filter the sys_user Reference variable to show only users whose "cmn_location" should only be Philippines.

Mycena Jane Cam
Tera Contributor

Hi I need the "dsrm_clientsname" to filter only the users whose country are Philippines. What should I do. Thanks.

 

find_real_file.png

find_real_file.png

4 REPLIES 4

Shubham Tipnis
Kilo Sage
Kilo Sage

Hi Mycena,

 

You can create a script include which returns all the users whose region is Philippines. Below is a sample code. 

var users  = '';
var user = new GlideRecord("sys_user");
user.addQuery("location.country","Philippines"); //dot walk the location field of the user from user profile.
user.query();
while(user.next()){
        users += user.sys_id;
    }
    return 'sys_idIN' + users;
	
		

 

You can then simple use the script in the ref qualifier like this:

 

javascript: x_api_name.functionName();

 

 

Please mark correct/helpful if applicable.

 

Regards,

Shubham

Regards,
Shubham Tipnis
 ServiceNow Enthusiast
️ 3x Rising Star (2022–2024) – ServiceNow Community
 Sharing insights, use cases & real-world learnings from the Now Platform
 Always learning. Always building.

what's wrong ?thanks

 

find_real_file.png

Try adding a comma after bracket on line 14. Also change Accessible from This scope to all applications.

Regards,
Shubham Tipnis
 ServiceNow Enthusiast
️ 3x Rising Star (2022–2024) – ServiceNow Community
 Sharing insights, use cases & real-world learnings from the Now Platform
 Always learning. Always building.

darwinsychangco
Tera Contributor

I looked for Philippine community and I ran across this entry. I know it's really old, but I just had to comment on this. You don't need to script this at all. You can simply just use "Simple" in the user Reference Qualifier and set the conditions.

Active | is | true AND

Country | is | Philippines

 

darwinsychangco_0-1723665292773.png

 

 

You definitely just want active users to be choices I'm sure, and as for the country, it's like dot walking. After setting active is true, click on the AND button. Expand the left side of the new condition and type location. If you don't see two results with the second one being "Location => Location fields", delete your search characters to see the complete list again. Scroll all the way down, and click on "Show Related Fields". Type "location" again and you'll see the second option; "Location => Location fields". Select that option. If you expand the left side of the condition again, you'll be presented with the Location [cmn_location] table fields. Simply select Country, keep the condition to is, and the right side is "Philippines.

 

This seems like a long read, but it's way shorter to actually do it.

 

Scripting looks cool and all, but but if you're creating a script include to just return a list of users whose country is Philippines (explicit), is not very wise. The country is set explicitly in the code, so it's not going to be reusable. Unless you think that in the future you think you'll need a reference qualifier that returns users whose country is something else, then yes by all means use a script include, name the method getUsersByCountry, and add an option parameter country.

 

getUsersByCountry: function(country) {

    var ret = [];

    var users = new GlideRecord('sys_user');

    users.addActiveQuery();

    users.addQuery('location.country', country);

    users.query();

    while(users.next()){

        ret.push(users.getUniqueValue());

    }

 

    return ret;

},