how to hide a view based on condition

Gopal14
Tera Contributor

Hi Team, how to hide a view based on condition.

I have created a view, I want to show that view only for group "HPC View group".

Below is my view rule script:

var currentUser = gs.getUser(); // Check if the current user is a member of the 'HPC View' group

if (currentUser.isMemberOf('HPC View group'))

{

// If the user is a member of the group, set the answer variable to 'HPC View'

var answer = "HPC View"; }

else { // If the user is not a member of the group, you might want to handle this case accordingly

var answer = "Not HPC View"; }

 

Script is not working, Can any one help

 

@Community Alums 

9 REPLIES 9

Mark Manders
Mega Patron

Even though you didn't ask me, you could try this if your script is client side:

 

(function onLoad() {
    var currentUser = gs.getUser();
    if (currentUser.isMemberOf('HPC View group')) {
        // Redirect or set the view if the user is part of the group
        g_form.setView('HPC View');
    } else {
        // Optionally redirect or hide the form/view if the user is not part of the group
        alert('You do not have permission to view this page.');
        window.history.back(); // Send them back to the previous page or to a default view
    }
})();

 

 or this if it is server side:

 

(function executeRule(current, previous /*null when async*/) {
    var currentUser = gs.getUser();
    if (!currentUser.isMemberOf('HPC View group')) {
        // Deny access by redirecting or showing an error
        current.addErrorMessage('You do not have access to this view.');
        action.setRedirectURL('some_default_page.do'); // Redirect to a default page
    }
    // If the user is a member, no action is needed; they'll see the view as intended
})();

 

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Gopal14 ,

 

Try: view rule script >

(function overrideView(view, is_list) {

if(gs.getUser().isMemberOf('HPC View group')) {
answer = "HPC View";
} else {
answer = "Not HPC View";
}

})(view, is_list);

 

I hope it helps !


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Hi @Sohail Khilji,

 

Still HPC View is visible.

See if there are any other rules overlapping it, instead of HPC view try for other view to see if the script is executing or not !


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect