UI Page: Turn Multi Row Variable set on Custom Table to HTML Table

Dazler
Mega Sage

Hi,

 

I am having the hardest time, trying to get a Multi-Row Variable Set from a Custom Table in to UI Page as an HTML Table.  I have queried the record and used "variables.name-of-variable-set" and when I set a log I can see the JSON, but when I try and pass it to a foreach loop in the HTML, I get nothing.  I even parsed the JSON before I added to the HTML and still nothing.  

What the need is, we have a custom application that has a record producer form request.  After ticket is submitted, sometimes the reps have to update the variables on the ticket and if they do they would need to print the form, just the variables, not the whole page.  The best approach is UI action to UI Page and pass the values directly to the UI Page form and automatically trigger the print after about 1000ms this gives a little time for the values to populate on the form.  I can pass just regular field values, but I can't get the MRVS to work.

 

Has anyone done this before?  Any help would be appreciated.

 

1 ACCEPTED SOLUTION

Robert H
Mega Sage

Hello @Dazler ,

 

Here is a working solution that I've verified on my end:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

    <!-- SERVER-SIDE JS: GET ARRAY OF OBJECTS -->
    <g:evaluate var="list" object="true">
        var gr = new GlideRecordSecure('sc_multi_row_question_answer');
        gr.addQuery('parent_id', 'SYS_ID OF TASK GOES HERE');
        gr.addQuery('variable_set.internal_name', 'INTERNAL NAME OF MRVS GOES HERE');
        gr.query();

        var results = {};
        while (gr.next()) {
        	var index = gr.getValue('row_index');
        	if (!results[index]) {
        		results[index] = {};
        	}
        	results[index][gr.item_option_new.name] = gr.value.toString();
        }

        var list = Object.keys(results).sort().map(rowId => results[rowId]);
    </g:evaluate>

    <table style="border:1px solid black !important;border-collapse:collapse !important;" width="100%" align="center" cellspacing="0" cellpadding="0">
        <thead>
            <tr style="background: sandybrown;">
                <th>Question 1</th>
                <th>Question 2</th>
                <th>Question 3</th>
                <th>Question 4</th>
            </tr>
        </thead>
        <tbody>
            <j:forEach var="jvar_row" items="${list}">
                <tr>
                    <td>${jvar_row['mrv_question_1']}</td>
                    <td>${jvar_row['mrv_question_2']}</td>
                    <td>${jvar_row['mrv_question_3']}</td>
                    <td>${jvar_row['mrv_question_4']}</td>
                </tr>
            </j:forEach>
        </tbody>
    </table>
</j:jelly>

 

Regards,

Robert

View solution in original post

7 REPLIES 7

Robert H
Mega Sage

Hello @Dazler ,

 

Here is a working solution that I've verified on my end:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

    <!-- SERVER-SIDE JS: GET ARRAY OF OBJECTS -->
    <g:evaluate var="list" object="true">
        var gr = new GlideRecordSecure('sc_multi_row_question_answer');
        gr.addQuery('parent_id', 'SYS_ID OF TASK GOES HERE');
        gr.addQuery('variable_set.internal_name', 'INTERNAL NAME OF MRVS GOES HERE');
        gr.query();

        var results = {};
        while (gr.next()) {
        	var index = gr.getValue('row_index');
        	if (!results[index]) {
        		results[index] = {};
        	}
        	results[index][gr.item_option_new.name] = gr.value.toString();
        }

        var list = Object.keys(results).sort().map(rowId => results[rowId]);
    </g:evaluate>

    <table style="border:1px solid black !important;border-collapse:collapse !important;" width="100%" align="center" cellspacing="0" cellpadding="0">
        <thead>
            <tr style="background: sandybrown;">
                <th>Question 1</th>
                <th>Question 2</th>
                <th>Question 3</th>
                <th>Question 4</th>
            </tr>
        </thead>
        <tbody>
            <j:forEach var="jvar_row" items="${list}">
                <tr>
                    <td>${jvar_row['mrv_question_1']}</td>
                    <td>${jvar_row['mrv_question_2']}</td>
                    <td>${jvar_row['mrv_question_3']}</td>
                    <td>${jvar_row['mrv_question_4']}</td>
                </tr>
            </j:forEach>
        </tbody>
    </table>
</j:jelly>

 

Regards,

Robert

Thank you, @Robert H. This worked.

donna_weiss
Giga Contributor

yes

Donna Weiss