How to check the empty of the glide object.

navyag
Kilo Contributor

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.

8 REPLIES 8

Mike Allen
Mega Sage

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>


I might have multiple records in the object , the above code returns only one record..


Brad Tilton
ServiceNow Employee
ServiceNow Employee

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.


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.