change field colors of risk assessment in project workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @MuhmmadU ,
You’re hitting a Workspace limitation, not really a coding problem
Your requirement is clear, but the approach you’re using will never work in Project Workspace. Let me explain why and then give you the correct, supported options.
Why your script is not working
1️Client scripts can’t style fields in Workspace
Your script uses this line:
g_form.getControl('summary_inherent_risk_score').style.backgroundColor = color;
This works only in Classic UI.
In Project Workspace / any Workspace (Now Experience UI):
- G_form.getControl() does not return a DOM element
- Direct CSS changes (.style.backgroundColor) are not supported
- Workspace UI is component-based and blocks DOM manipulation
So even a perfectly written script will not change colors in Workspace.
2️ Script bug (secondary issue)
Even in Classic UI, your script has a small bug:
test.style.backgroundColor = color;
But you defined:
backgroundColor = '#dc2626';
color is undefined.
You meant:
test.style.backgroundColor = backgroundColor;
Again—fixing this still won’t help in Workspace, but good to know.
Important rule to remember
Client scripts cannot control field background colors in Workspaces.
This is by design and cannot be overridden.
Supported ways to achieve this in Project Workspace
Option 1: UI Builder - Conditional Styling (Best solution)
This is the correct Workspace approach.
How:
- Open UI Builder
- Open Project Workspace
- Select the Form component
- Configure Conditional styles
- Add rules like:
- If summary_inherent_risk_score = High -Red
- If Moderate - Green
- If Low -Neutral
Supported
Upgrade-safe
Works for both Inherent & Residual fields
Option 2: Use badges / indicators instead of field color
Workspace works best with:
- Status pills
- Severity indicators
- Icons
Recommended pattern:
- Store risk as numeric or choice
- Display visual indicators instead of coloring the input field
What will NOT work
- Client scripts changing background color
- DOM manipulation
- CSS injection
- UI Policies for background color (Workspace ignores them)
(For reference only) Corrected script — Classic UI only
function onLoad() {
setRiskScoreColor();
}
function setRiskScoreColor() {
var scoreValue = g_form.getValue('summary_inherent_risk_score');
if (!scoreValue) return;
scoreValue = scoreValue.toLowerCase();
var backgroundColor = '#ffffff';
if (scoreValue.includes('high')) {
backgroundColor = '#dc2626';
} else if (scoreValue.includes('moderate')) {
backgroundColor = '#16a34a';
} else if (scoreValue.includes('low')) {
backgroundColor = '#ffffff';
}
var ctrl = g_form.getControl('summary_inherent_risk_score');
if (ctrl) {
ctrl.style.backgroundColor = backgroundColor;
}
}
This will not work in Project Workspace
If my response helped mark as helpful and accept the solution
