- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 11:49 AM
I have a need to build a dynamic table that will show up on a Catalog item.
I have a table that is used to populate the table. I was looking at some information out on the web and found that this could be done, but not having any luck getting it to produce the results.
I have a Rich Text Label named: efc_access_table that I want the script to populate.
I am using the code here for the Catalog Client Script: But it's not populating anything. The Catalog client script is set for onLoad for the catalog item and I'm not sure why it's not populating
function onLoad() {
// You can replace 'your_table_name' with the actual table you want to query
var gr = new GlideRecord('u_efc_choice');
gr.query();
// Create the HTML for the table dynamically
var tableHtml = '<style>';
tableHtml += 'table { width: 100%; border-collapse: collapse; }';
tableHtml += 'th, td { padding: 8px; text-align: left; border: 1px solid #ddd; }';
tableHtml += 'tr:nth-child(even) { background-color: #f2f2f2; }';
tableHtml += 'tr:nth-child(odd) { background-color: #ffffff; }';
tableHtml += '</style>';
tableHtml += '<table>';
tableHtml += '<thead><tr><th>Security Group</th><th>Description</th><th>Approver1</th><th>Approver2></th><th>Approver 3</th></tr></thead>';
tableHtml += '<tbody>';
// Loop through the records and add rows to the table
var rowCount = 0;
while (gr.next()) {
tableHtml += '<tr>';
tableHtml += '<td>' + gr.getValue('u_security_group') + '</td>';
tableHtml += '<td>' + gr.getValue('u_description') + '</td>';
tableHtml += '<td>' + gr.getValue('u_approver1.name') + '</td>';
tableHtml += '<td>' + gr.getValue('u_approver2.name') + '</td>';
tableHtml += '<td>' + gr.getValue('u_approver3.name') + '</td>';
tableHtml += '</tr>';
rowCount++;
}
tableHtml += '</tbody>';
tableHtml += '</table>';
// Inject the table HTML into the Rich Text field (e.g., with document.getElementById)
g_form.setValue('efc_access_table', tableHtml);
}
Has anyone created one of these that could shed some light on this please?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 07:48 AM
I was able to solve me own problem, I was using the g_form.setValue() function but it ended up I needed g_form.setLabelOf() function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 12:45 PM
Out of curiosity, why are you using a rich text label rather than a multi-row variable set or a custom widget?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 06:51 PM
It’s for a table on a catalog item that will just show the row data that I need. It’s more of a helper table for the user because you can’t put the pop-up help on a list collector
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 09:04 AM
Gotcha. If you need it to be editable, you can continue down the path of using a HTML-type variable (as Ankur mentioned below). If not, you can set that field read-only. Alternatively, you can use a custom widget. Either way, you'll use GlideAjax and a script include. If you need help getting started with GlideAjax, here's a post from a few weeks back that will help .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 08:51 PM
@Community Alums
GlideRecord won't work on portal
Also your variable should be of type HTML and not Rich Text
So here is the workaround
1) use onLoad catalog client script + GlideAjax
2) that script include function will return the HTML and you can set it directly in that variable and make that variable read-only
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader