2 Replies Latest reply on Jan 14, 2016 5:11 PM by SMGreenfield

    Count records with a certain flag

    MikeBriganti

      Title

      Count records with a certain flag

      Post

      I have a button on a screen that performs a script that is supposed to go through all records and display the number of records with a certain flag. 

      Script:

      As a test, I created two records and set their "IncompleteFlag = 1". Each time I press the count button, the count goes up by 1. (Rather then only displaying "2" no matter how many times the button is pressed.)

      As another test, when I set "IncompleteFlag = 0" on both records and pressed the count button, the count stays at zero. 

      Thank you for your help, I am not a very good programmer!

       

        • 1. Re: Count records with a certain flag
          philmodjunk

          The Go to Layout step immediately following the Set Field step makes no sense.

          Using a loop to count flagged records is very inefficient and needlessly complex.

          Other ways to count the records:

          1) Use a relationship that matches only to the flagged records you want to count. Then either the count function or a summary field can return the number of flagged records.

          2) perform a find for all flagged records. This can be done in a different window or in a different layout in order to leave your current found set unaltered. Get ( foundCount ) will then return the total number flagged records.

          3) ExecuteSQL could be used to count the number of Flagged records

          4) In some cases, a filtered portal with a summary field from the portal's table occurrence could be used to count records, but this value would be a "display" only count as it's difficult to access the count in such context for other uses.

          • 2. Re: Count records with a certain flag
            SMGreenfield

            Your reply on this topic appears to be the answer to my similar question:

             

            (this is a simplification of the actual process):

             

            I have a layout of table FOO.  Records of FOO have a field, FOO:IsSelected.  Some of those records may have FOO:IsSelected as 1, or 0.  The user presses a button to display how many records of the FOUND SET displayed in the layout on-screen have IsSelected = 1.  I do not wish to disrupt my found set.

             

            In your #1 answer, do I create a new Relationship (e.g. FOO_IsSelected) from table foo, and set that relationship from FOO matching the primary key of FOO (e.g. FOO:__pk_FooID) to itself in the new Relationship?  Then add an additional condition to the relationship that FOO:IsSelected = 1?  Then use Count (FOO_IsSelected)?

             

            In your answer #2, I totally get that I could create a new Window with the proper find parameters in a different Window / Layout.  On the surface this SEEMS inelegant (it would be nice if I could "Save" or "Push" a found set, narrow the found set, then "Restore" or "Pop" it right from the same Window / Layout. Since my goal is to display that count to the user, I'd rather not have any disruption of their list of found records on-screen.

             

            In your answer #3, I'm an SQL newb -- would you mind giving an example of how one might do this?

             

            Best Regards,

             

            Stephen