Zoho Deluge: Convert Map to HTML Table without a FOR loop

What?
A very quick article on converting a Map string into a HTML table without using a for each loop.

Why?
I have quite a big response from our CRM that hits a statement execution limit if I use a for loop. I have a map with 3 columns: first_name, last_name, and ID. What I want is a HTML table now with the headers and data but without using a for loop.

What I have:
{"First_Name":"Joel","Last_Name":"Lipman","id":"1"},{"First_Name":"Another","Last_Name":"Person","id":"2"}
What I want:
First NameLast NameID
JoelLipman1
AnotherPerson2

How?
This is a bit of a dirty solution and as long as "id" is not your first column (because "id" can be found in names like "David") it will work.

Assume a Map specified in deluge:
l_Data = List();
m_Data = Map();
m_Data.put("First_Name","Joel");
m_Data.put("Last_Name","Lipman");
m_Data.put("id","1");
l_Data.add(m_Data);
m_Data = Map();
m_Data.put("First_Name","Another");
m_Data.put("Last_Name","Person");
m_Data.put("id","2");
l_Data.add(m_Data);
v_Data = l_Data.toString();
info v_Data;

// yields
// {"First_Name":"Joel","Last_Name":"Lipman","id":"1"},{"First_Name":"Another","Last_Name":"Person","id":"2"}

Some formatting and a lot of replaceAll:
l_Keys = List();
l_Keys = v_Data.toMap().keys();
v_DataHtml = v_Data.replaceAll("},{", "}{", true);
v_DataHtml = v_DataHtml.replaceAll(l_Keys.get(0) + "\"", "<td>", true);
v_DataHtml = v_DataHtml.replaceAll("\",\"" + l_Keys.get(1) + "\"", "<td>", true);
v_DataHtml = v_DataHtml.replaceAll("\",\"" + l_Keys.get(2) + "\"", "</td><td>", true);
// tidy up
v_DataHtml = v_DataHtml.replaceAll("{", "<tr>", true);
v_DataHtml = v_DataHtml.replaceAll("\"}", "</td></tr>\n", true);
v_DataHtml = v_DataHtml.replaceAll(":\"", "", true);
v_DataHtml = v_DataHtml.replaceAll(">\"", ">", true);
v_DataHtml = v_DataHtml.replaceAll("\"<", "<", true);
info "<table>\n" + v_DataHtml + "</table>";

Related Articles

Joes Revolver Map

Joes Word Cloud

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 - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.