
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2015 09:09 AM
Hi all,
I'm trying something new (for me). I've got a UI Macro that I'm modifying.
I've added the following g:evaluate tag:
<g:evalute var="cart_count" object="true">
var cart_count = new GlideAggregate('sc_cart_item');
cart_count.addAggregate('SUM','quantity');
cart_count.addQuery('active','true');
cart_count.addQuery('sys_created_by',gs.getUserName());
cart_count.setGroup(false);
cart_count.query();
cart_count;
</g:evaluate>
The above code will give me a quantity for the number of catalog items I have in a shopping cart for the current user. This works great.
Later in the code, I have this <j:if> statement:
<j:if test="${cart_count.next()}">${cart_count.getAggregate('SUM','quantity')}</j:if>
The above code works great if all I want to show is how many items a user has in his/her cart.
What I'd like to do is throw an if statement that checks if the cart quantity for a user is 0:
if (SUM == 0/null) {
display '0'
}
else {
${cart_count.getAggregate('SUM','quantity')}
}
Obviously I have the 2nd half working, just not sure how to do the 1st half. Any help is greatly appreciated-
Matthew
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2015 11:23 AM
This worked for me:
<?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 jelly="true">
var cart_count = new GlideAggregate('sc_cart_item');
cart_count.addAggregate('SUM','quantity');
cart_count.addQuery('active','true');
cart_count.addQuery('sys_created_by',gs.getUserName());
cart_count.setGroup(false);
cart_count.query();
</g:evaluate>
<j:if test="${cart_count.next()}">
<j:choose>
<j:when test="${cart_count.getAggregate('SUM','quantity')} != 0">
Number of items: ${cart_count.getAggregate('SUM','quantity')}
</j:when>
<j:otherwise>
Number of items: 0
</j:otherwise>
</j:choose>
</j:if>
</j:jelly>
3 sc_cart_items:
After deleting the items:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2015 09:26 AM
Have the script as:
- <g:evalute var="javr_cart_count" object="true">
- var cart_count = new GlideRecord('sc_cart_item');
- cart_count.addQuery('active','true');
- cart_count.addQuery('sys_created_by',gs.getUserName());
- cart_count.query();
- var count = cart_Count.getRowCount();
- count;
- </g:evaluate>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2015 09:50 AM
Hi Mani,
Unfortunately this only returns the number of rows in sc_cart_item table. I need the total QUANTITY for all the rows for a specific user. Hence why i'm using glideAggregate.
Example, I have 1 record in sc_cart_item for iPhone6 with a quantity of 7. The above script will give me count = 1. I need 7
Matthew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2015 10:04 AM
you can use the quanity field on the sc_cart_item which will give you the quantity each item.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2015 10:16 AM
Mani,
Thanks for the reply.
Not sure I follow your logic here...
Matthew