Views

RadZz
Tera Contributor

Hello team,

 

I need to create a view where only people from assignment group, assigned to , collaborators and watchlist can see default view whereas everyone else should see restricted view.

I created restricted view. and title is : restricted view , name is : restricted_view.

 

so for view rules I wrote advanced and this doesn't work.

 

function overrideView(view, is_list) {
        var curr = gs.getCurrentRecord();
    var assignment = gs.assignment_group;
    var assigned = gs.assigned_to;
    var collaborators = gs.collaborators;
    var watch_list = gs.watch_list;
    var user = gs.getUser();

    if (user.isMemberOf(assignment) || user.getName() == assigned || user.isMemberOf(collaborators) || user.isMemberOf(watch_list)) {
        return view;
    } else {
        return 'Restricted View';
    }
}
 
Any help on what could be the issue or error?
 
 
TIA 🙂
 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@RadZz 

you cannot access field value using current object in view rule script

But here is a workaround and you can access the field value

The "current" object is not available in Advanced View Rule scripts although selectable in the scrip... 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@RadZz 

you cannot access field value using current object in view rule script

But here is a workaround and you can access the field value

The "current" object is not available in Advanced View Rule scripts although selectable in the scrip... 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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