The CreatorCon Call for Content is officially open! Get started here.

Gliderecord addQuery

servicetrout
Tera Expert

Running this exact code the count is always coming back as 500, but it should be > 2454 records.     If I look at the table the count   is

count.jpg

Any insight as to why this isn't returning the full set of names would be appreciated.

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading ) {

          return;

    }

    var idz = getDepts();

}

function getDepts() {

  var gr = new GlideRecord('u_badg_somrollup');          

  gr.addQuery('u_deptname' );

  gr.query();                                                                              

  var deptNames =[];                                                              

  i=-1;

    while(gr.next()) {

                    i++;

                    deptNames[i]=gr.u_deptname;

    }

      alert ("Returned Count: " + deptNames.length);     // 500

      return deptNames;

}

1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Glenn, your query uses the following WHERE clause:



gr.addQuery('u_deptname' );


Without a value there it means WHERE clause would be something like:



SELECT * FROM u_badg_somrollup WHERE u_deptname IS NULL;



Is this something you wanted on purpose?



Running this in Background scripts should give you the exact count you are getting:



var gr = new GlideRecord('u_badg_somrollup');        


  gr.addQuery('u_deptname' );


  gr.query();  


gs.print(gr.getRowCount());



If you had in mind a value for "u_deptname" the your query should look like:



gr.addQuery('u_deptname', <value>);

View solution in original post

8 REPLIES 8

Yes, this was part of the problem.   I had assumed excluding the operator and value meant it would return everything.


This worked better with gr.addQuery('u_deptname','DOES NOT CONTAIN', '').


Oddly enough, gr.addNotNullQuery('u_deptname') would not run.


However, the result set is still maxed out at 500 records (possibly a platform limit set by our administrator?) from a set that should have > 700 records.


So, I think Pradeep may be right that I need to look into using GlideAjax for this.   Having no knowledge of GlideAjax or Script Includes at this point, I feel like I'm playing Serena Williams without having a backhand.  



Thank you for your insight on this !



-G


divya mishra
Tera Guru

Hey Glenn,



If you just need the row count could you please try the below way :




var gr = new GlideRecord("u_badg_somrollup");


gr.query();


if(gr.next())


{


alert("Count is::"+gr.getRowCount());


}




Let me know if this was helpful/correct


Have a lovely day ahead




Regards,


Divya Mishra


I need a query that will return all 700+ department names.


Your script works fine, but I may have sprained my finger clicking through those alerts before I reach the end.



Thank you for your suggestion.



-G


There was an issue with one data record in the set.   Once I remove that record the queries worked as expected.



-G