Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Get Record Count of List using javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get Record Count of List using javascript

    I am trying to get the record count in a List Control using javascript before opening a report. This is because I want to prevent opening a report if there are over a certain number of records. I have tried the following 3 things and none of them work...

    Code:
    //the following one is from copying the one supplied by the defined Control to get record count 
    var countRec = {dialog.componentname}.list1.RECORDCOUNT;
    
    //I made the following one up
    var count = {dialog.Object}._getListRecordCount('LIST1');
    
    //I tried the following based on a thread in the forum
    var myOb = {dialog.Object}.getControl('LIST1');
    var countRec = myOb._data.length;
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  • #2
    Re: Get Record Count of List using javascript

    In case someone is curious, here is the whole thing I am trying to run...

    Code:
    //the following one is from copying the one supplied by the defined Control to get record count 
    var countRec = {dialog.componentname}.list1.RECORDCOUNT;
    
    //I made the following one up
    var count = {dialog.Object}._getListRecordCount('LIST1');
    
    //I tried the following based on a thread in the forum
    var myOb = {dialog.Object}.getControl('LIST1');
    var countRec = myOb._data.length;
    
    if(countRec > 5000){
    	alert('The report would have '+countRec+' records based on your search.  To prevent server overload, reports cannot be opened if they have more than 5000 records.  Please narrow down your search.');  
    } else {
    	if(countRec > 1000){
    		var answer = confirm('The report requested has over 1000 records and will take several moments to open.  Is it OK to continue?');
    		if(answer == true) {
    			{grid.object}.runAction('ReportPayrollLedgerByEmp');
    		} else {
    			alert('The action to open the report has been cancelled.');
    		}
    	} else {
    		{grid.object}.runAction('ReportPayrollLedgerByEmp');
    	}
    }
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

    Comment


    • #3
      Re: Get Record Count of List using javascript

      I can never remember if there is a method to get a list count... however, here are a couple of ways to do this...

      Your code does work...

      Code:
      var myOb = {dialog.Object}.getControl('LIST1');
      var countRec = myOb._data.length;

      Outside the List control...

      Code:
      var x = {dialog.Object}._listViewData.LIST1.length;
      where LIST1 (I believe in caps) is the name of your list control.

      And inside the List, in the onListDraw event you could save the count into a {dialog} namespace variable, and then use it elsewhere.

      Code:
      {dialog.Object}._myListCount = data.length;

      Comment


      • #4
        Re: Get Record Count of List using javascript

        Thanks, David, but I just tried the code below when 25,000 records were in the list control, and it ignored the count and just ran my action to open the report. This is being called by a button outside of the list control:

        Code:
        var countRec = {dialog.Object}._listViewData.LIST1.length;
        
        if(countRec > 5000){
        	alert('The report would have '+countRec+' records based on your search.  To prevent server overload, reports cannot be opened if they have more than 5000 records.  Please narrow down your search.');  
        } else {
        	if(countRec > 1000){
        		var answer = confirm('The report requested has over 1000 records and will take several moments to open.  Is it OK to continue?');
        		if(answer == true) {
        			{grid.object}.runAction('ReportPayrollLedgerByEmp');
        		} else {
        			alert('The action to open the report has been cancelled.');
        		}
        	} else {
        		{grid.object}.runAction('ReportPayrollLedgerByEmp');
        	}
        }
        Carol King
        Developer of Custom Homebuilders' Solutions (CHS)
        http://www.CHSBuilderSoftware.com

        Comment


        • #5
          Re: Get Record Count of List using javascript

          First of all... yikes... 25,000 in the List control. How long does that take to load?

          Anyway... I just tried this with your code... and if countRec is set below the threshold being tested, then the logic is ok. Do you have your List control set to Page data? Do you actually have 25,000 records loaded?

          Comment


          • #6
            Re: Get Record Count of List using javascript

            The list control is paginated to 50 records at a time, but the deffined control for record count shows the total of records in the query, the 25,000. I need to get the total count of the records because the report is based on CurrentListFilter and I don't want it to have too many records .... So that code I used is just returning the total of the paginated records?
            Carol King
            Developer of Custom Homebuilders' Solutions (CHS)
            http://www.CHSBuilderSoftware.com

            Comment


            • #7
              Re: Get Record Count of List using javascript

              The List control, when "pageinated" holds that number of records... there are no more records in the list. You say you have a defined control that displays the total count... grab that.

              Comment


              • #8
                Re: Get Record Count of List using javascript

                I tried, see my first post.. It didn't work. It's the code Aloha gives you in their defined controls list for record count
                Carol King
                Developer of Custom Homebuilders' Solutions (CHS)
                http://www.CHSBuilderSoftware.com

                Comment


                • #9
                  Re: Get Record Count of List using javascript

                  Sorry... can't resist... is Aloha the Hawaiian office of Alpha?

                  var countRec = parseInt($('{dialog.componentname}.LIST1.RECORDCOUNT').innerHTML);

                  The Defined Control, List-Record count, is a static text control, with data being rendered inside a <span> tag. So you need to get the innerHTML of the tag... where the value it. Then use parseInt to convert it to an integer.

                  Comment


                  • #10
                    Re: Get Record Count of List using javascript

                    David, thanks so much for your time. I tried, but when the defined control shows 23,182 records, your code returns 23
                    Carol King
                    Developer of Custom Homebuilders' Solutions (CHS)
                    http://www.CHSBuilderSoftware.com

                    Comment


                    • #11
                      Re: Get Record Count of List using javascript

                      Well, now for some reason it is returning NaN
                      Carol King
                      Developer of Custom Homebuilders' Solutions (CHS)
                      http://www.CHSBuilderSoftware.com

                      Comment


                      • #12
                        Re: Get Record Count of List using javascript

                        To get the number of rows in the List's Query (as opposed to the number of rows of data that the list is currently displaying) you can do this

                        var lObj = {dialog.object}.getControl('ID_of_your_list');
                        var count = lObj._state.recordCount;
                        alert(count);

                        obviously, if the list is not paginated then the number of rows shown in the list is the same as the number of rows in the list query (assuming that no client-side filter has been applied).

                        Comment


                        • #13
                          Re: Get Record Count of List using javascript

                          And to use your static text control...

                          var countRec = $('{dialog.componentname}.LIST1.RECORDCOUNT').innerHTML;
                          countRec = countRec.replace(/,/g,"")
                          countRec = parseInt(countRec);

                          Comment


                          • #14
                            Re: Get Record Count of List using javascript

                            Thank you, thank you, thank you, Selwyn. That worked. My list is paginated to 50 and the count showed the total of around 25000, AND I used a filter list control to do some searching and it also returned the right count. YAY!!! I'm sure that will help others that are trying to get that list record count into their inline javascript.
                            Carol King
                            Developer of Custom Homebuilders' Solutions (CHS)
                            http://www.CHSBuilderSoftware.com

                            Comment


                            • #15
                              Re: Get Record Count of List using javascript

                              David, thanks to you too!
                              Carol King
                              Developer of Custom Homebuilders' Solutions (CHS)
                              http://www.CHSBuilderSoftware.com

                              Comment

                              Working...
                              X