- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2016 01:28 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2016 05:35 AM
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() && maxloops ${AMP}lt; 5}">
${count.getAggregate('COUNT', 'abc')}
${maxloops += 1}
</j:while>
</j:jelly>
Regards,
Sergiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2016 02:02 AM
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
Thanks,
Sowmya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2016 05:35 AM
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() && maxloops ${AMP}lt; 5}">
${count.getAggregate('COUNT', 'abc')}
${maxloops += 1}
</j:while>
</j:jelly>
Regards,
Sergiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2016 05:57 AM
Hi Sergiu,
Thanks a lot for your great help. I did small change in while loop, instead of ${AMP}lt; I used < and it is working fine.
Please help me out in knowing the difference.
I have faced issue with ${AMP}lt; and <. Sometimes ${AMP} will work and sometimes <. May I know when we need to use what and what is the difference.
Thanks,
Sowmya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2016 06:09 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2016 03:52 AM
Hi Sergiu,
Thanks a lot.
Thanks,
Sowmya