why condition of user criteria true but the user can see the item

Fdeveloper
Kilo Guru

Hi,

in a catalog item i have in not available for a user criteria

if( new uc().haveBtw() && new uc().havelaptop() )
	answer = true;
else 
	answer = false;

in the script include i have 

 haveBtw: function() {
        gr.addEncodedQuery("principal=yes^model_category=27fab026dba43200cd8d7b9dae961948^ORmodel_category=affab026dba43200cd8d7b9dae961947^tagSTARTSWITHBTW^assigned_to=" + session.getClientData('requestor'));
        gr.query();
        while (gr.next()) return true;
        return false;
    },

    havelaptop: function() {
        var portable = "affab026dba43200cd8d7b9dae961947";
        var gr = new GlideRecord('hardware');
        gr.addQuery('model_category', portable);
        gr.addQuery('assigned_to', session.getClientData('requestor'));
        gr.query();
        while (gr.next()) return true;
        return false;
    },

when i check the hardware table user have all the condition true principal=yes , category = portable tagSTARTSWITHBTW , the user must not see the item because all the condition are true but i don't know wwhy yser cav view the item and even in user criteria diagnostic i get user can view the item

1 ACCEPTED SOLUTION

Please check user roles, user criteria always allow admin users to access records.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

8 REPLIES 8

Anil Lande
Kilo Patron

Hi,

Can you please update this part?

haveBtw: function() {
var gr= new GlideRecord('table_name'); // missing this line
        gr.addEncodedQuery("principal=yes^model_category=27fab026dba43200cd8d7b9dae961948^ORmodel_category=affab026dba43200cd8d7b9dae961947^tagSTARTSWITHBTW^assigned_to=" + session.getClientData('requestor'));
        gr.query();
        while (gr.next()) return true;
        return false;
    },

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

And you can improve the script like below:

haveBtw: function() {
var gr = new GlideRecord('tableName');        gr.addEncodedQuery("principal=yes^model_category=27fab026dba43200cd8d7b9dae961948^ORmodel_category=affab026dba43200cd8d7b9dae961947^tagSTARTSWITHBTW^assigned_to=" + session.getClientData('requestor'));
        gr.query();
        if (gr.hasNext())
            return true;
        return false;
    },

    havelaptop: function() {
        var portable = "affab026dba43200cd8d7b9dae961947";
        var gr = new GlideRecord('hardware');
        gr.addQuery('model_category', portable);
        gr.addQuery('assigned_to', session.getClientData('requestor'));
        gr.query();
        if (gr.hasNext()) 
            return true;
        return false;
    },

 

No need to use While and you can check presence by using hasNext().

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

hi @Anil Lande ,

Thank you for you reply, I found this problem just with one user I tested with another user when I checked I found the conditions of user criteria true and this second user don't see the item I do not know why the first user can see the item even  they have the same conditions principal=yes , category = portable tagSTARTSWITHBTW

 

Please check user roles, user criteria always allow admin users to access records.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande