8 Replies · Latest reply on Nov 6, 2017 1:28 PM by Glenn Strout

    Gliderecord addQuery

      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;

      }

        • Re: Gliderecord addQuery
          Pradeep Sharma

          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.

          - Pradeep Sharma (@sharma_pradeep)
          ServiceNow

          PS: Hit like, Helpful or Correct depending on the impact of the response

          • Re: Gliderecord addQuery
            sergiu.panaite

            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>);
            1 of 1 people found this helpful

            Best Regards,
            Sergiu

            Visit my community blog:
            https://community.servicenow.com/people/sergiu.panaite/blog

            or personal blog:
            http://bitsofcode.io

            Have a performance issue? Challenge me!

              • Re: Gliderecord addQuery
                Glenn Strout

                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

              • Re: Gliderecord addQuery
                Divya Mishra

                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