While Script in Jelly - UI Page

alexcharleswort
Tera Expert

Hi everyone,

I have a while script that is working just fine in my background script, I just can't seem to fit it into my UI Page the right way. I think I am really close but something is just off...

This is the script working as a background script:

var count2 = new GlideAggregate('u_uwb');

count2.addQuery('u_state', 20);

count2.addAggregate('COUNT', 'u_your_name');

count2.query();    

while (count2.next()) {

    var person2 = count2.u_your_name.getDisplayValue();

    var   personCount2 = count2.getAggregate('COUNT', 'u_your_name');  

}

I believe I am stuck on the 'while' loop part and assigning person2 and personCount2 their new values.

In my UI Page, I have this in the beginning:

<g:evaluate>

var count2 = new GlideAggregate('u_uwb');

count2.addQuery('u_state', 20);

count2.addAggregate('COUNT', 'u_your_name');

count2.query();    

while (count2.next()) {

  </g:evaluate>

and then later in the script when I try to fill out my table with the corresponding information I have the basic:

<table id="polines" width="90%" align="left" cellspacing="0" cellpadding="0">

          <thead>

              <tr>

                  <td class="header center" colspan="1">Name</td>            

              </tr>

          </thead>

          <j:while test="${count2.next()}"

>            

              <tr>

                  <td width="10%" align="left">${person2}</td>

      </tr>

          </j:while>

Anywhere I put the while loop bit in, my ui page comes up with the header but no records? Any idea where I should be putting this piece or if it should be formatted differently? I tried putting it right under the query and then also within the <j:while> tags but it's just not quite right.

Any help would be greatly appreciated!

Thanks!

1 ACCEPTED SOLUTION

krushikesh
Kilo Guru

Hi there ,



Try Below code


Crete New UI Page and paste code



<?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:evaluate>


var count2 = new GlideAggregate('incident');


count2.addQuery('state', 1);


count2.addAggregate('COUNT', 'caller_id');


count2.query();    


  </g:evaluate>


      <br />


      <table id="polines" width="90%" align="left" cellspacing="0" cellpadding="0">


          <thead>


              <tr>


                  <td class="header center" colspan="1">Name</td>        


               


                  <td class="header center" colspan="1">Count</td>        


              </tr>


          </thead>


          <j:while test="${count2.next()}">    


              <tr>


                  <td width="10%" align="left">${count2.caller_id.getDisplayValue(); }</td>  


   


                  <td width="10%" align="left">${count2.getAggregate('COUNT', 'caller_id');}</td>  


      </tr>


          </j:while>  


        </table>


      <br />


      <br />


</j:jelly>





If it work for you then replace your table and fields labels there




output on my side


find_real_file.png




View solution in original post

13 REPLIES 13

SanjivMeher
Kilo Patron
Kilo Patron

Remove line 7 and it should work


while (count2.next()) {  



Please mark this response as correct or helpful if it assisted you with your question.

  <g:evaluate>


var count2 = new GlideAggregate('u_uwb');


count2.addQuery('u_state', 20);


count2.addAggregate('COUNT', 'u_your_name');


count2.query();  


  var person2 = count2.u_your_name.getDisplayValue();


      var personCount2 = count2.getAggregate('COUNT', 'u_your_name');


  </g:evaluate>


      <br />


      <table id="polines" width="90%" align="left" cellspacing="0" cellpadding="0">


          <thead>


              <tr>


                  <td class="header center" colspan="1">Name</td>      


              </tr>


          </thead>


          <j:while test="${count2.next()}">  


              <tr>


                  <td width="10%" align="left">${person2}</td>


      </tr>


          </j:while>


        </table>


      <br />


      <br />


I had tried this before and it just returned a blank table. I tried it again and it did the same thing.


Hi there,



try below code



  1.   <g:evaluate>  
  2. var count2 = new GlideAggregate('u_uwb');  
  3. count2.addQuery('u_state', 20);  
  4. //count2.addAggregate('COUNT', 'u_your_name');  
  5. count2.query();      
  6. // var person2 = count2.u_your_name.getDisplayValue();  
  7.   //   var personCount2 = count2.getAggregate('COUNT', 'u_your_name');  
  8.   </g:evaluate>  
  9.       <br />  
  10.       <table id="polines" width="90%" align="left" cellspacing="0" cellpadding="0">  
  11.           <thead>  
  12.               <tr>  
  13.                   <td class="header center" colspan="1">Name</td>          
  14.               </tr>  
  15.           </thead>  
  16.           <j:while test="${count2.next()}">      
  17.               <tr>  
  18.                   <td width="10%" align="left">${count2.u_your_name.getDisplayValue();}</td>    
  19.       </tr>  
  20.           </j:while>    
  21.         </table>  
  22.       <br />  
  23.       <br />  


I have tested it on incident table and it display's values.



Have a great day


And I believe you are right, that will pull the person's name just fine.... but the personCount2 is what is missing. I need that to work.


if you just want the count of the users then you can use



count2.getRowCount();