Getting Error in Widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 05:20 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 05:34 PM - edited 01-03-2024 05:37 PM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 07:45 AM
Based on the code you added, how would it function if user doesnt have that role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 08:03 AM
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());
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 08:04 AM
It's always showing all records now and not following the else condition