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

Sainath N
Mega Sage
Mega Sage

@Michael48 : Please try with the below code assuming that users with only this role should be able to see the records. If not, I see that gs.getUser() statement missed (), please add () to gs.getUser in your script.

 

 

var del = [];

if (gs.getUser().hasRole("x_verw2_ac_factory.super_user")) {  // Checking the role condition here
    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());
    gr.query();
    while (gr.next()) {
        del.push(gr.number.toString());
    }
}

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution. 

Based on the code you added, how would it function if user doesnt have that role

i tried this 

 

 var gr = new GlideRecord('x_verw2_ac_factory_af_opportunity');
if (gs.getUser().hasRole("x_verw2_ac_factory.super_user")) {  // Checking the role condition here
    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());
    gr.query();
    while (gr.next()) {
        del.push(gr.number.toString());
    }
}
else{
//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());

gr.query();


while(gr.next()){
del.push(gr.number.toString());

}
}

It's always showing all records now and not following the else condition