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

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Glenn,




Can you provide some additional details on what you are trying to accomplish? Details are encouraged.


As a best practice, use GlideAjax calls for server-side calls. GlideRecord calls are not recommended from the client side.


I am trying to create a department selection field and a division selector in a record producer, which list only unique departments from a dept/division table that looks like this:



[


dept1     div1


dept1     div2


dept2     div3


dept2     div3


dept3     Null


dept4     div5


...


dept4     div54


...


]


Thanks for the update Glenn. In this case create a script include(client callable) and filter out the records per your logic and send back sysid as a response. Please check the example from below link as a reference and adjust it accordingly.


http://wiki.servicenow.com/index.php?title=Reference_Qualifiers


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>);