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 06:17 AM
What happens when you write it like this?
<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.hasNext()}">//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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 06:26 AM
For instance, if there 5 are records in the table , it is returning only 4 records, skipping the first record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 06:28 AM
It's because your if next() statement is iterating through the first record, did you replace it with hasNext() as in my example?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 07:19 AM
I did , but it is not working as expected when there is no record .