Need to highlight short description field of incident with some background color(blue/red etc)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 08:59 PM
Need to highlight short description field of incident with some background color(blue/red etc) in service operation workspace.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 09:06 PM
This can be done easily in UI builder, but I dont want to use UI builder as it will ask to create replica of the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 09:18 PM
I would personally recommend UI Builder approach because:
- It provides a structured way to modify widgets and their styles without interfering with the DOM.
- Direct DOM manipulation in workspaces can be brittle and prone to breaking during upgrades or changes.
However, if you want to avoid replicating forms in UI Builder, the below methods using client scripts and injected CSS should work.
1. Inject CSS Dynamically
if (g_event.isInteractive()) {
var shortDescriptionElement = document.querySelector('[sn-field-name="short_description"]');
if (shortDescriptionElement) {
shortDescriptionElement.style.backgroundColor = 'blue'; // Set your color
shortDescriptionElement.style.color = 'white'; // Adjust text color for contrast
}
}
2. Use Workspace Scripting API
// Event listener to customize the field
CustomEvent.observe('workspace-form-loaded', function() {
var fieldElement = document.querySelector('[sn-field-name="short_description"]');
if (fieldElement) {
fieldElement.style.backgroundColor = 'red'; // Background color
fieldElement.style.border = '1px solid black'; // Optional border
}
});
Hope you find this useful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 04:16 AM
Have you got any solution for this?