Changing a UI Builder component background color based on database value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2022 04:43 PM
I am building a UI builder page that is using a repeater with a stylized text component inside. I would like to change the background color of that text component based on a specific value from the database. (ie... if the value is "X" make the background color red, if it is "Y" make it blue otherwise make it yellow.) Does anyone have any ideas on how to accomplish this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2022 07:42 PM
Yes bind the CSS property with state parameter and change the value of state parameter with your logic.
The parameter will hold the whole CSS value.
ServiceNow Community Rising Star 2022/2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2022 09:57 AM
I set my state to below just to see if I could turn it green.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2022 07:02 PM
It should be like below. You missed * in the beginning.
*{
"color": "#00BB6659"
}
ServiceNow Community Rising Star 2022/2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2022 01:08 PM
Thank you for the information. I don't have a way to add the "*". The client state preview is read only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2023 02:33 AM
Yes the preview is read only. You can not modify the value from preview. You can update the state parameter directly.
ServiceNow Community Rising Star 2022/2023