Getting Error in Widget

Michael48
Tera Contributor

I have a code am working on where i want users with a specific role should be able to view the records in the query below. it seems to be working but its throwing the error in the screen shot.

 

Here is the code

 

var gr = new GlideRecord('x_verw2_ac_factory_af_opportunity');
gr.addQuery('u_state','!=','Draft');//only draft records should be visible
var grOr= gr.addQuery('u_requested_by' , gs.getUserID());
grOr.addOrCondition('requester_delegate',gs.getUserID());
grOr.addOrCondition(gs.getUser.hasRole("x_verw2_ac_factory.super_user")); //(my line of script that's throwing the error)
 
gr.query();
 
 
while(gr.next()){
del.push(gr.number.toString());
 
}
11 REPLIES 11

Hi @Michael48 the hasRole() method will always return true for admins, you can use hasRoleExacty() and also check your state values is it "draft" or "Draft" ?

Regards
Harish

when i try to use hasRoleExactly it throws error on the widget

 

I also tried to us sec admin as the role yet it allows people to see all

Harish KM
Kilo Patron
Kilo Patron

Hi @Michael48 you forgot to add () after gs.getUser.

gs.getUser().hasRole("x_verw2_ac_factory.super_user") // add ()

Regards
Harish

Ankur Bawiskar
Tera Patron
Tera Patron

@Michael48 

are you saying you want to check if requester_delegate user has that role or u_requested_by has that role?

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