For Zoho services only


I'm currently part of a wider delivery team at Ascent Business Solutions, recognised as a leading Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions support organisations with everything from targeted technical fixes through to full Zoho CRM implementations and long-term platform adoption. Working as a team rather than a one-person consultancy allows projects to move forward consistently, with access to the right skills at each stage.

The team I manage specialises in API integrations between Zoho and third-party finance and commerce platforms such as Xero, Shopify, WooCommerce, and eBay. Much of our work involves solving integration challenges that fall outside standard documentation, supporting new ideas, new sectors, and evolving business models.

Success is measured through practical outcomes and return on investment, ranging from scaling small operations into high-turnover businesses to delivering rapid gains through online payments, automation, and streamlined digital workflows.

If you are looking for structured Zoho expertise backed by an established consultancy, you can contact Ascent Business Solutions on 0121 392 8140 (UK), email info@ascentbusiness.co.uk, or visit https://www.ascentbusiness.co.uk.
Zoho Deluge: Convert Hex to RGB

Zoho Deluge: Convert Hex to RGB

What?
A quick article to document a Zoho Deluge function converting a hexadecimal color reference to a Red Green Blue value (RGB).

Why?
It's likely that Zoho will avail their color picker at some point as an input but at the time of print, this hasn't happened yet. Here's a function in deluge that takes a 3 or 6 character hexadecimal color and returns the RGB values for you.

How?
Very quickly, we take each character from the given string and convert it to its RGB value. Replace letters A to F with their numeric equivalents. Made up of 2 characters to convert to an RGB subset, the 1st value is to be multiplied by 16 and then added to the value of the 2nd; this equals the RGB value.

Given #00FF00
copyraw
// 
// given value
v_HexGiven = "#00FF00";
//
// transform or format the submitted value
v_HexValue = v_HexGiven.replaceAll("#", "").toUpperCase();
//
// using a regular expression: split into pairs of characters or if short hex given, then split into 3 characters
l_HexParts = v_HexValue.replaceAll("(?)",",",false).toList().subList(1,4);
if(v_HexGiven.toString().len()>4)
{
	l_HexParts = v_HexValue.replaceAll("(?<=\\G..)",",",false).toList().subList(0,3);
}
//
// declare our output variable and map the characters to a value
l_RgbResult = List();
m_HexMap = {"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"A":10,"B":11,"C":12,"D":13,"E":14,"F":15};
//
// loop through the 3 parts of the given hex and add to a list
for each v_HexPart in l_HexParts
{
	v_HexConvert = if(v_HexPart.toString().len()==1, v_HexPart.toString() + v_HexPart.toString(), v_HexPart).toString();
	v_Rgb_1 = m_HexMap.get(v_HexConvert.subString(0,1)) * 16;
	v_Rgb_2 = m_HexMap.get(v_HexConvert.subString(1,2));
	v_Rgb_Sum = v_Rgb_1 + v_Rgb_2;
	l_RgbResult.add(v_Rgb_Sum);
}
//
// output
info "rgb(" + l_RgbResult.toList() + ")";
// yields rgb(0,255,0)
  1.  // 
  2.  // given value 
  3.  v_HexGiven = "#00FF00"; 
  4.  // 
  5.  // transform or format the submitted value 
  6.  v_HexValue = v_HexGiven.replaceAll("#", "").toUpperCase()
  7.  // 
  8.  // using a regular expression: split into pairs of characters or if short hex given, then split into 3 characters 
  9.  l_HexParts = v_HexValue.replaceAll("(?)",",",false).toList().subList(1,4)
  10.  if(v_HexGiven.toString().len()>4) 
  11.  { 
  12.      l_HexParts = v_HexValue.replaceAll("(?<=\\G..)",",",false).toList().subList(0,3)
  13.  } 
  14.  // 
  15.  // declare our output variable and map the characters to a value 
  16.  l_RgbResult = List()
  17.  m_HexMap = {"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"A":10,"B":11,"C":12,"D":13,"E":14,"F":15}
  18.  // 
  19.  // loop through the 3 parts of the given hex and add to a list 
  20.  for each v_HexPart in l_HexParts 
  21.  { 
  22.      v_HexConvert = if(v_HexPart.toString().len()==1, v_HexPart.toString() + v_HexPart.toString(), v_HexPart).toString()
  23.      v_Rgb_1 = m_HexMap.get(v_HexConvert.subString(0,1)) * 16
  24.      v_Rgb_2 = m_HexMap.get(v_HexConvert.subString(1,2))
  25.      v_Rgb_Sum = v_Rgb_1 + v_Rgb_2; 
  26.      l_RgbResult.add(v_Rgb_Sum)
  27.  } 
  28.  // 
  29.  // output 
  30.  info "rgb(" + l_RgbResult.toList() + ")"
  31.  // yields rgb(0,255,0) 

Note(s):
If using this in CRM, note that the regular expression here needs the escaping(-escaping) backslash to be omitted:
copyraw
l_HexParts = v_HexValue.replaceAll("(?<=\G..)",",",false).toList().subList(0,3);
  1.  l_HexParts = v_HexValue.replaceAll("(?<=\G..)",",",false).toList().subList(0,3)

Testing it out
copyraw
v_HexGiven = "#0f0";
// yields: rgb(0,255,0)

v_HexGiven = "#dcf02c";
// yields: rgb(220,240,44)
  1.  v_HexGiven = "#0f0"; 
  2.  // yields: rgb(0,255,0) 
  3.   
  4.  v_HexGiven = "#dcf02c"; 
  5.  // yields: rgb(220,240,44) 

Broken Down / Simplified:
copyraw
v_1stHex = v_HexGiven.subString(0,2);
v_2ndHex = v_HexGiven.subString(2,4);
v_3rdHex = v_HexGiven.subString(4,6);
//
v_Rgb_1 = m_HexNumbers.get(v_1stHex.subString(0,1)) * 16;
v_Rgb_2 = m_HexNumbers.get(v_1stHex.subString(1,2));
v_1stRgb = v_Rgb_1 + v_Rgb_2;
//
v_Rgb_1 = m_HexNumbers.get(v_2ndHex.subString(0,1)) * 16;
v_Rgb_2 = m_HexNumbers.get(v_2ndHex.subString(1,2));
v_2ndRgb = v_Rgb_1 + v_Rgb_2;
//
v_Rgb_1 = m_HexNumbers.get(v_3rdHex.subString(0,1)) * 16;
v_Rgb_2 = m_HexNumbers.get(v_3rdHex.subString(1,2));
v_3rdRgb = v_Rgb_1 + v_Rgb_2;
//
info "rgb(" + v_1stRgb + "," + v_2ndRgb + "," + v_3rdRgb + ")";
  1.  v_1stHex = v_HexGiven.subString(0,2)
  2.  v_2ndHex = v_HexGiven.subString(2,4)
  3.  v_3rdHex = v_HexGiven.subString(4,6)
  4.  // 
  5.  v_Rgb_1 = m_HexNumbers.get(v_1stHex.subString(0,1)) * 16
  6.  v_Rgb_2 = m_HexNumbers.get(v_1stHex.subString(1,2))
  7.  v_1stRgb = v_Rgb_1 + v_Rgb_2; 
  8.  // 
  9.  v_Rgb_1 = m_HexNumbers.get(v_2ndHex.subString(0,1)) * 16
  10.  v_Rgb_2 = m_HexNumbers.get(v_2ndHex.subString(1,2))
  11.  v_2ndRgb = v_Rgb_1 + v_Rgb_2; 
  12.  // 
  13.  v_Rgb_1 = m_HexNumbers.get(v_3rdHex.subString(0,1)) * 16
  14.  v_Rgb_2 = m_HexNumbers.get(v_3rdHex.subString(1,2))
  15.  v_3rdRgb = v_Rgb_1 + v_Rgb_2; 
  16.  // 
  17.  info "rgb(" + v_1stRgb + "," + v_2ndRgb + "," + v_3rdRgb + ")"

Vice-Versa: Code Snippet to convert RGB to Hex
Even easier than our Hex to RGB, same as above but in reverse:
copyraw
// 
// given value (note that a list of 3 values are submitted to this)
l_RgbRequest = ifnull(p_RGB,{0,0,0});
// 
// list to map the value to a character
l_RgbList = {0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"};
// 
// loop through the 3 parts of the given hex and add to a list 
v_HexResult = "#";
for each  v_RgbPart in l_RgbRequest
{
	//
	// quotient: divide rgb by 16 for 1st character
	v_Hex_1 = floor(v_RgbPart / 16);
	//
	// remainder/modulus: get remainder from division of rgb by 16
	v_Hex_2 = v_RgbPart % 16;
	//
	// concatenate these 2 characters to our output string
	v_HexResult = v_HexResult + l_RgbList.get(v_Hex_1).toString() + l_RgbList.get(v_Hex_2).toString();
}
// 
// output 
return v_HexResult;
  1.  // 
  2.  // given value (note that a list of 3 values are submitted to this) 
  3.  l_RgbRequest = ifnull(p_RGB,{0,0,0})
  4.  // 
  5.  // list to map the value to a character 
  6.  l_RgbList = {0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"}
  7.  // 
  8.  // loop through the 3 parts of the given hex and add to a list 
  9.  v_HexResult = "#"; 
  10.  for each  v_RgbPart in l_RgbRequest 
  11.  { 
  12.      // 
  13.      // quotient: divide rgb by 16 for 1st character 
  14.      v_Hex_1 = floor(v_RgbPart / 16)
  15.      // 
  16.      // remainder/modulus: get remainder from division of rgb by 16 
  17.      v_Hex_2 = v_RgbPart % 16
  18.      // 
  19.      // concatenate these 2 characters to our output string 
  20.      v_HexResult = v_HexResult + l_RgbList.get(v_Hex_1).toString() + l_RgbList.get(v_Hex_2).toString()
  21.  } 
  22.  // 
  23.  // output 
  24.  return v_HexResult; 
If put in a function:
copyraw
// given
l_Given = {11,255,128};
info thisapp.Color_Picker.fn_RGBToHex(l_Given);
// yields #0BFF80
  1.  // given 
  2.  l_Given = {11,255,128}
  3.  info thisapp.Color_Picker.fn_RGBToHex(l_Given)
  4.  // yields #0BFF80 


Category: Zoho Deluge :: Article: 413

Accreditation

Badge - Zoho Creator Certified Developer Associate
Badge - Zoho Deluge Certified Developer
Badge - Certified Zoho CRM Developer

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com