For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at https://ascentbusiness.co.uk/zoho-services/uk-zoho-support.  For larger projects, talk to our experts and receive dedicated support from our hands-on project consultants at https://ascentbusiness.co.uk/zoho-services/zoho-crm-implementation.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at https://ascentbusiness.co.uk.

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 :: Article: 885

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

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

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
© 2024 Joel Lipman .com. All Rights Reserved.