Can we use one GlideRecord for multiple use

sowmyaj
Giga Expert

Hi All,

        I have used "GlideRecord"   for my custom table which is highlighted below. I'm using the same "GlideRecord variable" for number of times as highlighted in my code. I'm able to fetch the data's under first while loop only but I want it to work in other while loops too.

       

        I added all tables under different div and also under <g2> tag and also tried under single div and <g2> tag, but I'm not getting data's. Can any one suggest me the possible ways to resolve this issue.

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

<style>

My style goes here..........

</style>

<body>
  <br/>
 
<table style="float: right">
  <tr>
    <td><a href="u_training_plan.do" class="button"><b>Register Trainings</b></a>
    </td>
  </tr>
</table>
 
<br/>

<!-- Below is the GlideRecord-->


<g:evaluate object="true">
var trainings = new GlideRecord('u_training_plan');
trainings.query();
</g:evaluate>


<div>


<table class="a2_table">
<tr>
  <th colspan="5" class="a2_th"><h4><b>Trainings Recommended</b></h4></th>
</tr>
<tr>
  <th class="a2_th"><b>Name </b> </th>
  <th class="a2_th"> <b>Trainings </b></th>
  <th class="a2_th"><b> Status </b> </th>
</tr>

<j:while test="${trainings.next()}">
  <j:if test="${trainings.u_status == 'Recommended'}">
  <tr>
    <td class="a2_td">${trainings.u_name.getDisplayValue()} </td>
          <td class="a2_td">${trainings.u_trainings.getDisplayValue()} </td>
          <td class="a2_td">${trainings.u_status} </td>
  </tr>
    </j:if>
</j:while>

</table>
 
  <br/>
 
<table class="a2_table">
<tr>
  <th colspan="5" class="a2_th"><h4><b>Trainings Planned</b></h4></th>
</tr>
<tr>
  <th class="a2_th"><b>Name </b> </th>
  <th class="a2_th"> <b>Trainings </b></th>
  <th class="a2_th"><b> Status </b> </th>
</tr>

<j:while test="${trainings.next()}">
  <j:if test="${trainings.u_status == 'Enrolled'}">
  <tr>
    <td class="a2_td">${trainings.u_name.getDisplayValue()} </td>
          <td class="a2_td">${trainings.u_trainings.getDisplayValue()} </td>
          <td class="a2_td">${trainings.u_status} </td>
  </tr>
    </j:if>
</j:while>
</table>

  <br/>
 
<table class="a2_table">
<tr>
  <th colspan="5" class="a2_th"><h4><b>Trainings Completed</b></h4></th>
</tr>
<tr>
  <th class="a2_th"><b>Name </b> </th>
  <th class="a2_th"> <b>Trainings </b></th>
  <th class="a2_th"><b> Status </b> </th>
</tr>

  <j:while test="${trainings.next()}">
  <j:if test="${trainings.u_status == 'Completed'}">
  <tr>
    <td class="a2_td">${trainings.u_name.getDisplayValue()} </td>
          <td class="a2_td">${trainings.u_trainings.getDisplayValue()} </td>
          <td class="a2_td">${trainings.u_status} </td>
  </tr>
  </j:if>
  </j:while>
</table>
   
</div>
</body>
</html>
</g:ui_form>  
</j:jelly>

Thanks,

Sowmya

1 ACCEPTED SOLUTION

Valor1
Giga Guru

Try this -- after the first and second of your "</j:while>" tags, do the following:


<g:evaluate>


trainings.setLocation(-1);


</g:evaluate>


View solution in original post

6 REPLIES 6

nikita_mironov
Kilo Guru

Any idea how this can be done with scoped GlideRecord where setLocation method is not available?

Unfortunately, you'll have to rerun the query. If your code is dependent on having the same variable name, it's not ideal but you can reuse the same var name (e.g. "trainings" in the example above).