Create Advanced Script on User Criteria for locations

mkader
Kilo Guru

Hello,

I am trying to create an Advanced Script for User Criteria to make a content item available for certain locations. There are about 100 locations that the content item should be available for. Below is the script that I am using and is not working.

checkCondition();

function checkCondition() {
    var queryString = 'city=Sacramento^ORcity=Wichita';
    var gr = new GlideRecord('cmn_location');
        gr.addEncodedQuery(queryString);
        gr.query();
    if (gr.hasrNext()) {
        answer = true;
    } 
	
	return false;
}

Any idea on what I am doing wrong?

Thanks!

16 REPLIES 16

Hi,

Usually the User Criteria evaluates for logged in user and if it satisfied it shows the catalog item

if the location of the user has empty City then it doesn't make sense having User Criteria

Regards

Ankur

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

@Ankur Bawiskar  can you please look at the response by alikutty above. I am unsure of how to make this work. Are there any other alternatives to this?

Hi,

yes he rightly said. Ideally your users in sys_user table should have locations associated to their profile and location table should have city and all other information

If everything is setup correctly i.e. users have location and location have city; then no need of advance user criteria directly you can give the locations for which this catalog item should be visible

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

Is there a test script I can use to see what data is being pulled back?

Hi,

How is your user table loaded? Is somebody manually loading the data using some template using data source. Do they have location value populated

Check LDAP is configured in the instance which might be pulling the data

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