how to color code the columns based on role in list view on workspace dashboard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 07:39 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 10:13 PM
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:
-
Identify the Target Field: Determine which field in the table section you want to apply the color code to.
-
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.
-
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:
- Go to the UI Form configuration.
- Add a new Client Script record.
- Paste the script into the script field.
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 06:01 AM
Thank you for reply but I wish to do the same in workspace, how to color code the column in workspace dashboards