User Criteria not working!

Sri56
Tera Contributor

Hi Team,

I have build a user criteria to restrict my catalog items for germany users.

So, below is the screenshot of my user criteria

]

When i check for logs, sometimes working and sometimes not and all users are able to view the catalog item.

even though i mapped this user criteria in not availability column.

There is nothing in available column.

Can someone please help me how to fix this?

 

Thanks,

Sri

12 REPLIES 12

Aman Kumar S
Kilo Patron

Keep return false as last statement in the function and remove from if condition, only keep return true there

Best Regards
Aman Kumar

Hi Aman,

Thanks for the response,

I have changed to below code:

gs.log("Inside: All German Users");
answer = checkCondition();

function checkCondition() {
    var userGr = new GlideRecord("sys_user");
    var curuser = gs.getUserID();
    gs.log("current user for user criteria:::" + curuser);
    userGr.addQuery('sys_id', curuser);
    userGr.query();
    if (userGr.next()) {
        if (userGr.location.country == 'DE')
            return true;
    }
    return false;
}

But still No luck!

 

Please help!

 

Thanks,

Sri

tripu
Tera Expert

Hi Sri,

Please find the format for the Scripted User Criteria.

/** Scripted User Criteria is not cached, and evaluated everytime, so performance is dependent on the script.
* Populate `answer` with true/false or evaluate to true/false
* The script is evaluated in the scope the user criteria is defined
* Don't use `current` in the script or populate the variable
* Don't use `gs.getUser()` or  `gs.getUserID()`, 
* instead use `user_id` which contains the user sys_id against whom the evaluation is happening.
*/

Instead of gs.getUserId(), use 'user_id' as per the instructions.

Please mark the answer correct if this answers your question.

Regards,

Tripu

Sri56
Tera Contributor

Hi Tripu,

Still no luck!

 

Thanks,

Sri

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So if location -> country is Germany then you want to block it

How are you determining the country as Germany?

Regards
Ankur

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