3 Replies Latest reply on Aug 12, 2013 7:21 AM by philmodjunk

    Limit selection based on ID



      Limit selection based on ID


           I have a hospital database that contains multiple contacts at the same hospital. I'm trying to limit the number of names selected to 6 or less per hospital. The script below gives me half of the available names so if there are 20 records at a hospital it is giving me 10 and if there are 6 it is giving me 3. Anyone have any thoughts?

           Sort Records [ Specified Sort Order: HOSP::HOSPID; ascending ]
           [ Restore; No dialog ]
           Go to Record/Request/Page[ First ]
           Set Variable [ $id; Value:"" ]
           Set Variable [ $counter; Value:1 ]
           If [ HOSP::HOSPID ≠ HOSP::HOSPID ]
           Set Variable [ $id; Value:"HOSPID" ]
           Set Variable [ $counter; Value:1 ]
           End If
           If [ $counter ≥ 6 ]
           Omit Record
           Set Variable [ $counter; Value:$counter+1 ]
           End If
           Go to Record/Request/Page
           [ Next; Exit after last ]
           End Loop
           Any help would be appreciated.

        • 1. Re: Limit selection based on ID

               why are you setting the $counter back to 1 in each loop?, it looks like it should be incrementing, suggest you debug if you have FMPA..

               I'm also assuming that you're using $id elsewhere in the script - otherwise why invoke it?

          • 2. Re: Limit selection based on ID

                 I created the two variables $id and $counter to keep track of HOSPID as it loops through the records and to count a maximum of 6 records per ID.

            • 3. Re: Limit selection based on ID

                   If [ HOSP::HOSPID ≠ HOSP::HOSPID ]

                   Will never be true any more than 5 ≠ 5 will ever be true.

                   and this step:

                   Set Variable [ $id; Value:"HOSPID" ]

                   Sets the variable $id to the letters HOSPID every time that it executes.

                   I am guessing that you meant to do this:

                   If [ HOSP::HOSPID ≠ $id ]
                      Set Variable [ $id; Value:HOSP::HOSPID ]

                   But there are much simpler ways to reduce your found set to just the first 6 records:

                   Sort Records [Restore ; No Dialog ]
                   Go to Record/Request/Page [first]
                   If [ Get ( FoundCount ) > 6 ]
                      Go to Record/Request/Page [7 ; no dialog]
                      Omit Multiple Records [ Get ( FoundCount ) ; no dialog ]
                   End IF