How do I access MRVS values in a UI page?

sbh
Tera Guru

Thanks to many of you, I can easily access MRVS values in a script include or client script but I know next to nothing about jelly. I've created a UI page which lists certain request items and I have no trouble listing regular variables but I can't figure out how to list MRVS values. I want to list the first 7 rows of the Funding Sources MRVS and I'm clearly not using g:evaluate or j:forEach correctly. Thanks in advance for your help!

 

<tr>

...
<th>Date Submitted</th>
<th>Submitted By</th>
<th>Event Dates</th>
<th>Event Location</th>

...
<th>Funder 1 Name</th>
<th>Fund 1 #</th>
<th>Org 1 #</th>
<th>Fund 1 $</th>
<th>Fund 1 Type</th>
<th>Funder 2 Name</th>
<th>Fund 2 #</th>
<th>Org 2 #</th>
<th>Fund 2 $</th>
<th>Fund 2 Type</th>

'''
<th>Funder 7 Name</th>
<th>Fund 7 #</th>
<th>Org 7 #</th>
<th>Fund 7 $</th>
<th>Fund 7 Type</th>
</tr>
<g:evaluate jelly="true">
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item.name', 'Travel Authorization Form');
ritm.orderByDesc('number');
ritm.query();
</g:evaluate>
<g:for_each_record file="${ritm}">
<tr>

...
<td>${ritm.opened_at}</td>
<td>${ritm.opened_by.name}</td>

...

<g2:evaluate jelly="true" object="true" var="jvar_mrvs">
var mrvs = ritm.variables.u_sk_travel_funding_sources;
</g2:evaluate>
<j:forEach var="jvar_mrvs" begin="0" end="6" items="${fund}">
<td>${jvar_mrvs.getRow(${fund}).u_sk_funder_name}</td>
<td>${jvar_mrvs.getRow(${fund}).u_sk_fund_number}</td>
<td>${jvar_mrvs.getRow(${fund}).u_sk_org_number}</td>
<td>${jvar_mrvs.getRow(${fund}).u_sk_funder_amt}</td>
<td>${jvar_mrvs.getRow(${fund}).u_sk_funding_type}</td>
</j:forEach>

 

1 ACCEPTED SOLUTION

sbh
Tera Guru

Got it (got the data anyway)! Many thanks to HI for responding to an urgent plea, pointing out my syntax and mixed phase errors, directing me to @Chuck Tomasi 's great videos (video1, video2, and video3), and for the suggestion that the rest of the problem lay in the way I was attempting to access the MRVS values. When I queried the Multi Row Question Answer table and ordered the table by row index, then by variable order number, I had the data I needed in the order I needed it. I didn't figure out in time how to prettify it - it's a ragged-edged table (see the attached screenshot) - but it can be copied to an Excel sheet and sorted, etc. there so it meets the needs of the users who requested it. I experimented a little with placing blanks in the cells and then writing over the blanks with values but couldn't get that to work. But here's the code I ended up with:

<tr>
	<!-- Other table headers here -->
	<th>Funder 1 Name</th>
	<th>Fund 1 #</th>
	<th>Org 1 #</th>
	<th>Fund 1 $</th>
	<th>Fund 1 Type</th>
	<!-- Repeat the above headers for Funder 2 to Funder 7 -->
</tr>

<g:evaluate jelly="true">
	var ritm = new GlideRecord('sc_req_item');
	ritm.addQuery('cat_item.name', 'Travel Authorization Form');
	ritm.orderByDesc('number');
	ritm.query();
</g:evaluate>

<g:for_each_record file="${ritm}">
	<tr>
		<!-- Other table cells here -->

		<g:evaluate>
			var fundsrc=new GlideRecord('sc_multi_row_question_answer');
			fundSrc.addQuery('parent_id', ritm.sys_id);
			fundSrc.orderBy('row_index');
			fundSrc.orderBy('item_option_new.order');
			fundSrc.query();
		</g:evaluate>
		<g:for_each_record file="${fundSrc}">
			<td>${fundSrc.value.toString()}</td>
		</g:for_each_record>
	</tr>
</g:for_each_record>  <!-- close for-each ritm -->

 (see attached 

View solution in original post

4 REPLIES 4

Chaitanya Redd1
Tera Guru

Hi,

 

Can you try below code.

 

 

...
<th>Funder 1 Name</th>
<th>Fund 1 #</th>
<th>Org 1 #</th>
<th>Fund 1 $</th>
<th>Fund 1 Type</th>
<th>Funder 2 Name</th>
<th>Fund 2 #</th>
<th>Org 2 #</th>
<th>Fund 2 $</th>
<th>Fund 2 Type</th>
...
<th>Funder 7 Name</th>
<th>Fund 7 #</th>
<th>Org 7 #</th>
<th>Fund 7 $</th>
<th>Fund 7 Type</th>
</tr>
<g:evaluate jelly="true">
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item.name', 'Travel Authorization Form');
ritm.orderByDesc('number');
ritm.query();
</g:evaluate>
<g:each var="item" items="${ritm}">
<tr>
...
<td>${item.opened_at}</td>
<td>${item.opened_by.name}</td>
...
<g:evaluate jelly="true">
var mrvs = new GlideRecord('u_sk_travel_funding_sources');
mrvs.addQuery('request_item', item.sys_id);
mrvs.orderBy('sys_created_on');
mrvs.query();
</g:evaluate>
<g:evaluate jelly="true">
var maxRows = 7;
</g:evaluate>
<g:evaluate jelly="true">
var fund = 1;
while (mrvs.next() && fund <= maxRows) {
  var funderName = mrvs.u_sk_funder_name.getDisplayValue();
  var fundNumber = mrvs.u_sk_fund_number.getDisplayValue();
  var orgNumber = mrvs.u_sk_org_number.getDisplayValue();
  var fundAmount = mrvs.u_sk_funder_amt.getDisplayValue();
  var fundType = mrvs.u_sk_funding_type.getDisplayValue();
  
  var rowNumber = (fund % 7 == 0) ? 7 : (fund % 7);
  var columnNumber = Math.ceil(fund / 7);
  
  var rowSelector = 'tr:nth-child(' + (rowNumber + 1) + ')';
  var columnSelector = 'td:nth-child(' + (columnNumber + 1) + ')';
  
  var rowHtml = '<tr>' +
    '<td>' + funderName + '</td>' +
    '<td>' + fundNumber + '</td>' +
    '<td>' + orgNumber + '</td>' +
    '<td>' + fundAmount + '</td>' +
    '<td>' + fundType + '</td>' +
    '</tr>';
  
  jellyContext.append(rowSelector, columnSelector, rowHtml);
  
  fund++;
}
</g:evaluate>
<j:forEach var="jvar_mrvs" begin="0" end="6" items="${fund}">
<td>${jvar_mrvs.getRow(${fund}).u_sk_funder_name}</td>
<td>${jvar_mrvs.getRow(${fund}).u_sk_fund_number}</td>
<td>${jvar_mrvs.getRow(${fund}).u_sk_org_number}</td>
<td>${jvar_mrvs.getRow(${fund}).u_sk_funder_amt}</td>
<td>${jvar_mrvs.getRow(${fund}).u_sk_funding_type}</td>
</j:forEach>

 

Amit Gujarathi
Giga Sage
Giga Sage

HI @sbh ,
I trust you are doing great.
First, you need to create a UI page with the desired HTML structure. Assuming you have already done that, I'll focus on the specific code segment where you want to display the MRVS values.

<tr>
<!-- Other table headers here -->
<th>Funder 1 Name</th>
<th>Fund 1 #</th>
<th>Org 1 #</th>
<th>Fund 1 $</th>
<th>Fund 1 Type</th>
<!-- Repeat the above headers for Funder 2 to Funder 7 -->
</tr>

<g:evaluate jelly="true">
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item.name', 'Travel Authorization Form');
ritm.orderByDesc('number');
ritm.query();
</g:evaluate>

<g:for_each_record file="${ritm}">
<tr>
<!-- Other table cells here -->
<td>${ritm.opened_at}</td>
<td>${ritm.opened_by.name}</td>
<!-- Other table cells here -->

<g2:evaluate jelly="true" object="true" var="jvar_mrvs">
var mrvs = ritm.variables.u_sk_travel_funding_sources;
</g2:evaluate>

<j:forEach var="fund" begin="0" end="6" items="${jvar_mrvs}">
<td>${fund.u_sk_funder_name}</td>
<td>${fund.u_sk_fund_number}</td>
<td>${fund.u_sk_org_number}</td>
<td>${fund.u_sk_funder_amt}</td>
<td>${fund.u_sk_funding_type}</td>
</j:forEach>
</tr>
</g:for_each_record>


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



sbh
Tera Guru

@Chaitanya Redd1, @Amit Gujarathi  - Thank you both very much for your prompt responses! Neither of these solutions worked for me as is, but they've given me some ideas to work with.

sbh
Tera Guru

Got it (got the data anyway)! Many thanks to HI for responding to an urgent plea, pointing out my syntax and mixed phase errors, directing me to @Chuck Tomasi 's great videos (video1, video2, and video3), and for the suggestion that the rest of the problem lay in the way I was attempting to access the MRVS values. When I queried the Multi Row Question Answer table and ordered the table by row index, then by variable order number, I had the data I needed in the order I needed it. I didn't figure out in time how to prettify it - it's a ragged-edged table (see the attached screenshot) - but it can be copied to an Excel sheet and sorted, etc. there so it meets the needs of the users who requested it. I experimented a little with placing blanks in the cells and then writing over the blanks with values but couldn't get that to work. But here's the code I ended up with:

<tr>
	<!-- Other table headers here -->
	<th>Funder 1 Name</th>
	<th>Fund 1 #</th>
	<th>Org 1 #</th>
	<th>Fund 1 $</th>
	<th>Fund 1 Type</th>
	<!-- Repeat the above headers for Funder 2 to Funder 7 -->
</tr>

<g:evaluate jelly="true">
	var ritm = new GlideRecord('sc_req_item');
	ritm.addQuery('cat_item.name', 'Travel Authorization Form');
	ritm.orderByDesc('number');
	ritm.query();
</g:evaluate>

<g:for_each_record file="${ritm}">
	<tr>
		<!-- Other table cells here -->

		<g:evaluate>
			var fundsrc=new GlideRecord('sc_multi_row_question_answer');
			fundSrc.addQuery('parent_id', ritm.sys_id);
			fundSrc.orderBy('row_index');
			fundSrc.orderBy('item_option_new.order');
			fundSrc.query();
		</g:evaluate>
		<g:for_each_record file="${fundSrc}">
			<td>${fundSrc.value.toString()}</td>
		</g:for_each_record>
	</tr>
</g:for_each_record>  <!-- close for-each ritm -->

 (see attached