Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Has Anyone created a dynamic ricktext label for a catalog item that uses a catalog client script?

Not applicable

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?

1 ACCEPTED SOLUTION

Not applicable

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.

View solution in original post

6 REPLIES 6

Not applicable

Could you help me out with the code on this. I've never done this and am still learning. Would be a great opportunity to learn something 🙂

Not applicable

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.