Glide aggregate max

sowmyaj
Giga Expert

Hi All,

        I'm not able to get the maximum count.

                            Based on my requirement I have result as 'A(value) - 3(count)' , 'B(value) - 3(count)', 'C(value) - 6(count)', 'D(value) - 10(count)', 'E(value) - 2(count)', 'F(value) - 1(count)','G(value) - 7(count)'.

                            Now, I need to find the MAX of above result. Also I need to display top "FIVE" MAX count.

Initial step I tried as below to get the "MAX" count but didn't get the expected result.

        <g:evaluate>

              var inc=new GlideAggregate('incident');

                          inc.addQuery(   My queries   )

                          inc.addAggregate('COUNT','abc');     <!-- abc is a column in incident table-->

                          inc.addAggregate('MAX','abc');  

                        inc.query();

      </g:evaluate>

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

            ${inc.getAggregate('COUNT', 'abc')}

        ${inc.getAggregate('MAX', 'abc')}

        </j:while>

Can anyone help me to resolve this!!!!

Thanks,

Sowmya

1 ACCEPTED SOLUTION

Hi Sowmya,



Can you try something like:



<?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 count = new GlideAggregate('incident');


  count.addAggregate('COUNT','abc');


  count.orderByAggregate('COUNT','abc');


  count.query();


  var maxloops = 0;    


</g:evaluate>




<j:while test="${count.next() &amp;&amp; maxloops ${AMP}lt; 5}">  


  ${count.getAggregate('COUNT', 'abc')}


  ${maxloops += 1}


</j:while>


</j:jelly>



Regards,


Sergiu


View solution in original post

9 REPLIES 9

Hi Sergiu,



                  Thanks a lot. My requirement is same as above.   Can you please post the code snippet using <g:evaluate> and <j> tags because when I'm checking two conditions in while loop using "${AMP} / &&" I'm failing.



It will be a great help for me if you post the code snippet.




I have modified your code based on my requirement and the code snippet is as below



<?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 count = new GlideAggregate('incident');  


count.addAggregate('COUNT','abc');  


count.orderByAggregate('COUNT','abc');  


count.query();        


</g:evaluate>


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


${count.getAggregate('COUNT', 'abc')}


</j:while>


</j:jelly>



and result is


Untitled.png



Thanks,


Sowmya


Hi Sowmya,



Can you try something like:



<?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 count = new GlideAggregate('incident');


  count.addAggregate('COUNT','abc');


  count.orderByAggregate('COUNT','abc');


  count.query();


  var maxloops = 0;    


</g:evaluate>




<j:while test="${count.next() &amp;&amp; maxloops ${AMP}lt; 5}">  


  ${count.getAggregate('COUNT', 'abc')}


  ${maxloops += 1}


</j:while>


</j:jelly>



Regards,


Sergiu


Hi Sergiu,



                  Thanks a lot for your great help. I did small change in while loop, instead of ${AMP}lt; I used &lt; and it is working fine.



                  Please help me out in knowing the difference.


                            I have faced issue with ${AMP}lt; and &lt;. Sometimes ${AMP} will work and sometimes &lt;. May I know when we need to use what and what is the difference.



Thanks,


Sowmya.


I also thought ${AMP} is required here per:



Extensions to Jelly Syntax - ServiceNow Wiki



but it seems you required the HTML format:



How to Escape in Jelly - ServiceNow Wiki



Regards,


Sergiu


Hi Sergiu,



        Thanks a lot.



Thanks,


Sowmya