How to insert a condition in a User Criteria from two different tables

pjftenorio
Tera Expert
(function isAllowed() {
    var gr = new GlideRecord('sys_user');
    gr.addQuery('sys_id', 'sysparm_user');
    gr.addQuery('active', 'true');
    gr.addQuery('sso_source', gs.getProperty('*SOME PROPERTY*'));
    gr.query();
    if (gr.hasNext()) {
        var usergr = new GlideRecord('sys_user_has_role');
        usergr.addQuery('state', 'active');
        usergr.addQuery('role', '*ROLES*'); 
        usergr.query();
        return usergr.next();
    }
})();

How do I use the gliderecord for two different table?

5 REPLIES 5

James Chun
Kilo Patron

Hi @pjftenorio,

 

Why are you querying the [sys_user] and [sys_user_has_role] tables?

Can't you just query the [sys_user_has_role] table?

 

Cheers

Hi James, I have a custom field in the sys_user table which is the SSO ID of a user, then I need to get the role from that user in sys_user_has_role table.

So you are checking if the current user's SSO ID is equivalent to a system property and if the user has a certain role?

If so, can't you do something like the following instead?

JamesChun_0-1715803547146.png

 

 

Naomi5
Giga Guru

Hi, 

 

I am assuming your requirement is. "If the user fits xyz requirement in sys_user table and also fits the abc requirement in sys_user_has_role table; then the user pass the user criteria", yes?