Skip to content

Commit 7566048

Browse files
authored
Created Client Script to Conditional Display of Section on User Role (#1566)
* Create README.md * Create script.js
1 parent 3ae1cc4 commit 7566048

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Conditional Form Sections Based on User Role
2+
3+
## Overview
4+
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).
5+
6+
## Use Case
7+
- Managers: Can see the Budget Approval section.
8+
- Other Users: The section remains hidden.
9+
10+
## How It Works
11+
- The script runs onLoad of the form.
12+
- It checks if the logged-in user has the specified role (manager in this example).
13+
- If the user has the role, the Budget Approval section is shown. If not, it remains hidden.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function onLoad() {
2+
var userHasRole = g_user.hasRole('case_manager'); // Check if user has specific role
3+
4+
if (userHasRole) {
5+
g_form.setSectionDisplay('budget_approval', true); // Show section if user has specific role
6+
} else {
7+
g_form.setSectionDisplay('budget_approval', false);
8+
}
9+
}

0 commit comments

Comments
 (0)