Font Size:
Ask Joget AI

Restrict UI Menu Visibility Based on Registered Users

Introduction

This article describes how to configure Joget DX to show or hide a specific UI menu based on whether the currently logged-in user is registered in a particular form table.

Joget does not provide a native option to dynamically assign menu permissions based on form data. However, this requirement can be achieved by applying a BeanShell Permission directly to the menu that should be restricted.

With this approach, the menu will only be visible if the logged-in user exists in the designated form table.

How Does It Work

Restrict a specific menu visibility using BeanShell Permission

If you only want to show or hide a specific UI menu based on whether the logged-in user is registered in the form table:

  1. In UI Builder, select the UI Category to which the menus are to be restricted.
  2. Under Permission Setting, choose BeanShell in the Permission Type dropdown.
  3. Paste the BeanShell script used to detect the logged-in user:
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import org.joget.apps.app.service.AppUtil;
    import org.joget.commons.util.LogUtil;
    
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    Boolean isUserAccessible = false;
    
    try {
        String currentUser = "#currentUser.username#";
    
        con = (Connection) AppUtil.getApplicationContext().getBean("setupDataSource").getConnection();
    
        String sql = "SELECT c_sub_user FROM app_fd_submittedForm WHERE c_sub_user = ?";
        ps = con.prepareStatement(sql);
        ps.setString(1, currentUser);
        rs = ps.executeQuery();
    
        if (rs.next()) {
            isUserAccessible = true;
            LogUtil.debug("SQL Result", "User found: " + rs.getString("c_sub_user"));
        }
    } catch (Exception e) {
        LogUtil.error("SQL Error", e, e.getMessage());
    } finally {
        try {
            if (rs != null) rs.close();
            if (ps != null) ps.close();
            if (con != null) con.close();
        } catch (Exception ex) {
            LogUtil.error("Closing Error", ex, ex.getMessage());
        }
    }
    
    return isUserAccessible;

    The BeanShell script checks whether the logged-in user (#currentUser.username#) exists in the form table (e.g., app_fd_submittedForm), and if found, it allows menu access; otherwise, it denies access.

  4. Click Apply Change.

Expected Outcome

The Manage Submit Form menu is visible to Admin users when the current logged-in user (#currentUser.username#) exists in the form table.

When logged in as Cat, the Manage Submit Form menu is not displayed and cannot be accessed by the user.

Download sample app

Download the demo app for Restrict UI Menu Visibility Based on Registered Users:
Created by Debanraj Ravindran Last modified by Nurkhairini Fitrah on May 18, 2026