How to check the empty of the glide object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 04:27 AM
Hi Team,
I am fetching the records from the table, i used if condition to check the emptiness of the glide object if the object contain the record , the if condition will run and it skip the first record of the glide object.
Find the below snippet which we have used to fetch the data and checking the emptiness of the object.
<g:evaluate var="jvar_gr" object="true">
var gr = new GlideRecord("table_name");
gr.addQuery('type','degradation').addOrCondition('condition','a');
gr.query();
gr;
</g:evaluate>
<j:if test="${!jvar_gr.next()}">//when this script runs if the records are present in the object it skipping the first record of the object.
no records;
</j:if>
<j:while test="${jvar_gr.next()}">
//statements
</j:while>
Please give suggestion to avoid the skipping of the first record.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 04:47 AM
I would use j:choose, as in:
<j:choose>
<j:when test="${jvar_gr.next()}">
//statements
</j:when>
<j:otherwise>
no records;
</j:otherwise>
</j:choose>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 06:14 AM
I might have multiple records in the object , the above code returns only one record..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 06:05 AM
If you're just trying to test whether a gliderecord contains a record, and not actually stepping into the records, you can use hasNext() instead of next. hasNext() returns true or false depending on whether your object has any records, but doesn't affect the records within the object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 06:14 AM
Its working fine, if there is a record in the object.But if there is no record in the object, the if condition is not working as expected.