Skip to content

Created Client Script to Conditional Display of Section on User Role #1566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Client Scripts/Conditional Form Section based on Role/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Conditional Form Sections Based on User Role

## Overview
This client script dynamically shows or hides specific sections of a form based on the logged-in user’s role. It ensures that only authorized users, such as managers, can view and interact with sensitive sections (e.g., budget approvals).

## Use Case
- Managers: Can see the Budget Approval section.
- Other Users: The section remains hidden.

## How It Works
- The script runs onLoad of the form.
- It checks if the logged-in user has the specified role (manager in this example).
- If the user has the role, the Budget Approval section is shown. If not, it remains hidden.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function onLoad() {
var userHasRole = g_user.hasRole('case_manager'); // Check if user has specific role

if (userHasRole) {
g_form.setSectionDisplay('budget_approval', true); // Show section if user has specific role
} else {
g_form.setSectionDisplay('budget_approval', false);
}
}
Loading