how to color code the columns based on role in list view on workspace dashboard

SivaranjaniR
ServiceNow Employee
ServiceNow Employee

applied a color code on section in a  table  based on UI FORM for specific view but changes is not reflect on the workspace dashboard

2 REPLIES 2

Vaishnavi Lathk
Mega Sage
Mega Sage

Hello,

To apply color codes to a section in a table based on a UI form for a specific view in ServiceNow, you can utilize client-side scripting. Here's a general outline of how you can achieve this:

  1. Identify the Target Field: Determine which field in the table section you want to apply the color code to.

  2. Write Client Script: Write a client script to run on the UI form when it loads. This script will apply the color code based on the value of the field.

  3. Attach Client Script to UI Form: Associate the client script with the UI form so that it executes when the form loads.

Here's an example of how you can write the client script:

function applyColorCode() {
    // Get the value of the field you want to base the color code on
    var fieldValue = g_form.getValue('field_name');

    // Define the color codes based on the field value
    var colorCode = '';
    switch (fieldValue) {
        case 'value1':
            colorCode = '#FF0000'; // Red
            break;
        case 'value2':
            colorCode = '#00FF00'; // Green
            break;
        // Add more cases for additional values if needed
        default:
            colorCode = ''; // Default color or no color change
            break;
    }

    // Apply the color code to the table section
    var sectionElement = document.getElementById('section_id'); // Replace 'section_id' with the actual ID of the section
    if (sectionElement) {
        sectionElement.style.backgroundColor = colorCode;
    }
}

// Run the function when the UI form loads
addLoadEvent(applyColorCode);

In this script:

  • field_name should be replaced with the actual name of the field in the UI form.
  • value1, value2, etc., represent the values of the field that you want to base the color code on. Adjust these values according to your specific requirements.
  • section_id should be replaced with the actual ID of the table section where you want to apply the color code.

Once you've written the script, you can attach it to the UI form:

  1. Go to the UI Form configuration.
  2. Add a new Client Script record.
  3. Paste the script into the script field.
  4. Save the Client Script record.

Ensure that the UI Form is associated with the correct table and that it is used in the specific view you're targeting.

 
Regards,
Vaishnavi Lathkar
 
 
 
 

Thank you for reply but   I wish to do the same in workspace, how to color code the column in workspace dashboards