The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.
Mar 28, 2024 07:49 AM
Hi Community!
I would like generate with a formula a random hex color code for each new record in a database. How can I do that?
Thank you for your help!
Stefan
Mar 28, 2024 10:37 AM
If you want a truly random system, you will need a script. Put the script in an automation that runs when the record is created.
If you are okay with a pseudo random system, it is theoretically possible to generate a hex color code from the record ID, but that would be a very long, complex formula. I think that a script would be easier.
Mar 28, 2024 04:11 PM
Pseudo-random is fine. My main motivation is just to change the color / hex code a bit within a variation of posts.
Mar 29, 2024 03:48 AM - edited Mar 30, 2024 10:04 AM
Hi,
It's an interesting question, a translation between numeric system from base 62 to base 16
I would get last char of RECORD_ID(),
4*FIND(LEFT(RIGHT(RECORD_ID(),1)),
'abcdefghijklmnopqrstuvwxyz'&
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'&
'0123456789')
4 - to get a range from 4 to 248
then get 2 chars:
mid('01234567890ABCDEF',X,1)
where X
1+int(Y/16)
1+mod(Y,16)
where Y is upper formula.
and then repeat two times, changing number 1 in upper formula to 2,3
the result should look quite complex. but nothing ever easy 🙂