Welcome to Portal

?Unknown\pull-down

Welcome to Zoho Cares

Bienvenido a Soporte de Zoho

Search our knowledge base, ask the community or submit a request.

Hi!

I'm trying to create an HTML Snippet on a page in Zoho Creator and would like to create an HTML table pulled from a list of time entries that I have in a form. I have successfully pulled the collection of time entries, but the code that I have built to put these entries into a table is only returning one row / one entry into that table. I'm using the "for each" function. Does anyone know if I'm doing something wrong?

This is the code:

<%
filteredrecords = Task_Details[Log_Date >= input.start_date && Log_Date <= input.end_date] sort by Log_Date desc;
for each  entry in filteredrecords
{
logdate = entry.Log_Date;
tasktype = filteredrecords.Task_Type;
tasknotes = filteredrecords.Task_Notes;
loggedhours = filteredrecords.Time_Spent;
entryid = filteredrecords.Time_Entry_ID;
tablebody = "<td>" + entryid + "</td>" + "<td>" + logdate + "</td>" + "<td>" + tasktype + "</td>" + "<td>" + tasknotes + "</td>" + "<td>" + loggedhours + "</td>";
}
%>
<table>
<tr>
<th>ID</th>
<th>Log Date</th>
<th>Task Type</th>
<th>Task Notes</th>
<th>Time Spent</th>
</tr>
<tr>
<td><%=tablebody%></td>
</tr>
</table>
<%

}%>

Attachments
Screenshot 2025-01-16 at 12.20.35 PM.png
Screenshot 2025-01-16 at 12.20.35 PM.png15 KB
1 user has this problem.
6 Replies
Reply
  • Zoho MVP
  • 26 days ago

Its looks like mis formed HTML

This row, <td><%=tablebody%></td> remove the td tags so its just <%=tablebody%> as you have the td tags in the body istelf

  • Zoho MVP
  • 26 days ago

Looks like you will need to include the "<tr>" tags for each row within your "tablebody" variable, otherwise it'll include all the cells within one row. Something like:
  1. <%
  2. filteredrecords = Task_Details[Log_Date >= input.start_date && Log_Date <= input.end_date] sort by Log_Date desc;
  3. for each  entry in filteredrecords
  4. {
  5. logdate = entry.Log_Date;
  6. tasktype = filteredrecords.Task_Type;
  7. tasknotes = filteredrecords.Task_Notes;
  8. loggedhours = filteredrecords.Time_Spent;
  9. entryid = filteredrecords.Time_Entry_ID;
  10. tablebody
    = "<tr><td>" + entryid + "</td>" + "<td>" + logdate +
    "</td>" + "<td>" + tasktype + "</td>" + "<td>" +
    tasknotes + "</td>" + "<td>" + loggedhours + "</td></tr>";
  11. }
  12. %>
  13. <table>
  14. <tr>
  15. <th>ID</th>
  16. <th>Log Date</th>
  17. <th>Task Type</th>
  18. <th>Task Notes</th>
  19. <th>Time Spent</th>
  20. </tr>
  21. <%=tablebody%>
  22. </table>
  23. <%

  24. }%>

Hello!

Step 1: Create a table template in Zoho Mail or Excel (save Excel file as .html format)

Step 2: Select the HTML edit option and copy the entire code.

Step 3: Paste it into a Creator page and replace the values with variables, such as `<=name>`.

Step 4: Run a for loop to generate the rows dynamically.

 
 - thank you both for the ideas! I fixed the HTML but unfortunately it's still not iterating to add all of the rows :( 

  • Zoho MVP
  • 25 days ago

You need to add "tablebody" outside the loop and add to it for each iteration, like:
  1.     <%
  2.         filteredrecords = Task_Details[Log_Date >= input.start_date && Log_Date <= input.end_date] sort by Log_Date desc;
  3. tablebody = "";
  4.         for each  entry in filteredrecords
  5.         {
  6.             logdate = entry.Log_Date;
  7.             tasktype = filteredrecords.Task_Type;
  8.             tasknotes = filteredrecords.Task_Notes;
  9.             loggedhours = filteredrecords.Time_Spent;
  10.             entryid = filteredrecords.Time_Entry_ID;
  11.             tablebody += "<tr><td>" + entryid + "</td>" + "<td>" + logdate +
  12.     "</td>" + "<td>" + tasktype + "</td>" + "<td>" +
  13.     tasknotes + "</td>" + "<td>" + loggedhours + "</td></tr>";
  14.         }
  15.         %>
  16.     <table>
  17.         <tr>
  18.             <th>ID</th>
  19.             <th>Log Date</th>
  20.             <th>Task Type</th>
  21.             <th>Task Notes</th>
  22.             <th>Time Spent</th>
  23.         </tr>
  24.         <%=tablebody%>
  25.     </table>
  26.     <%
  27.     }%>

 - that worked!! Thank you so much!

Reply to Jaclyn PooleA
/* */
  • 12
  • Insert
  • Plain text
Add Comment
(Up to 20 MB )