Convert Colors to Hex Value Using JSON()


First off – why might you want to do this?

In my case, I already had a complex switch statement that decided the color of a button, and I wanted to match that button in an HTML control.

In this example, I have applied a gradient to these kanban cards that matches the color assigned to the departments in another place in the app. To achieve this, simply wrap the “component.color” in JSON like so:

JSON(Button.Color)

If this is not returning the hex value correctly, in my case it was returning an extra quotation mark, make use of “Mid” to trim the excess from the beginning like so:

Mid(JSON(Button.Color),2,7)