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

snowtech1
Tera Expert

Try this



<g:evaluate jelly="true">  


var count2 = new GlideAggregate('u_uwb');  


count2.addQuery('u_state', 20);  


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


count2.query();        


count2;


</g:evaluate>  





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


<div>${count2.sys_id} <div>


</j:while>


I think this is missing the bit that would return my needed value for personCount2


athm
Tera Guru

Hi Alex,



As I cant see your whole UI Page, I thought the below example should help you out



<g:evaluate>


      var agg = new GlideAggregate('your_table_here);


      agg.addAggregate('COUNT', 'your_field_here');


      agg.query();


//Here you dont need to check while(agg.next()) instead you can check at a later point in your script as below in a jelly tag


</g:evaluate>



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


                                      <!-- Do your stuff here -->


    </j:while>



Hope this helps.


find_real_file.png


I keep getting this error....


find_real_file.png