change field colors of risk assessment in project workspace

MuhmmadU
Tera Contributor
function onLoad() { //Type appropriate comment here, and begin script below setRiskScoreColor(); } function setRiskScoreColor() { // Change field name if needed var scoreValue = g_form.getValue('summary_inherent_risk_score'); if (!scoreValue) return; scoreValue = scoreValue.toLowerCase(); backgroundColor = "#dc2626"; //HIGH -> RED if (scoreValue.includes("high")) { backgroundColor = '#dc2626'; } // MODERATE -> GREEN else if (scoreValue.includes('moderate')) { backgroundColor = '#16a34a'; } // LOW -> WHITE else if (scoreValue.includes('low')) { backgroundColor = '#ffffff'; } // EXACT SAME STYLE APPLICATION AS YOUR RISK RANK SCRIPT var test = g_form.getControl('summary_inherent_risk_score'); test.style.backgroundColor = color; // g_form.getControl('owner').setStyle('color:#151920'); } my query is that i want to field my inherent and residual colors after they getting filled with their risk scores in prject workspace on basis of this workspace but that script is not working so give me suggestion
1 REPLY 1

AnkaRaoB
Giga Guru

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:

  1. Open UI Builder
  2. Open Project Workspace
  3. Select the Form component
  4. Configure Conditional styles
  5. 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