4 Replies Latest reply on Apr 20, 2015 12:52 AM by Henry_2

    Getting the next number in a value list with a script

    swillette

      Title

      Getting the next number in a value list with a script

      Post

      In FileMaker Pro Advanced 12 on Windows, I have a drop down menu based on Value List that is getting it's values from a field in another table/layout in the database based on a found set.

      It works great, but my users want a forward and back button to browse the records.

      Is there a way to write a script to find the next value in the Value List?

      I need the next value because of all the other find criteria in the script. 

        • 1. Re: Getting the next number in a value list with a script
          philmodjunk

          I'm afraid that I don't see how a forward and back button to browse records (You have this already in the tool bar and can also add your own buttons for this to a layout), has anything to do with the values in a value list.

          The values in a value list can be selected in any order so "previous" and "next" seem pretty hard to determine in that context.

          • 2. Re: Getting the next number in a value list with a script
            swillette

            There are all kiinds of relationships in my DB including some ODBC tables. My scripts have different found sets for each of the tables/layouts.

            It's hard to explain in words, but the user goes to the next record by a dropdown menu based on a Value List. 

            The forward and back buttons will not work based on all the different find criteria.

            My dropdown script does a find in a table based on a couple of criteria, copies the records into another copy table, then the dropdown menu gets the found set values from a Value List that is based on a field from that copy table. My dropdown menu is a global field.

            I need to write a script that can go to the next project number in the Value List.

            • 3. Re: Getting the next number in a value list with a script
              philmodjunk

              Try this script for "next". I'll call the field formatted with the drop down list Globals::DropDown and will assume that it is a global field.

              Set Variable [$Values ; value: valueListItems ( Get ( FileName ) ; "YourValueListNameInQuotesHere" ) ]

              IF [ Globals::DropDown ≠ GetValue ( $Values ; ValueCount ( $Values ) ) ]
                 Set Field [ Globals::DropDown ;
                                 Let ( [ D = Globals::DropDown;
                                           L = Length ( D ) ;
                                           v = $Values & ¶ ;
                                           pV = Position ( v ; D ; 1 ; 1 ) ;
                                           End = Position ( v ; ¶ ; pV ; 2 )
                                         ];
                                          Middle ( v ; pV + L + 1 ; End - pV - L - 1 )
                                        ) ]
              End IF

              • 4. Re: Getting the next number in a value list with a script
                Henry_2

                Stumbled on this when searching for Previous/Next navigation in a list. For those who like the script for previous as well:

                Set Variable [$Values ; value: valueListItems ( Get ( FileName ) ; "YourValueListNameInQuotesHere" ) ]

                IF [ Globals::DropDown ≠ GetValue ( $Values ; 1 ) ]
                   
                Set Field [ Globals::DropDown ;
                                   Let ( [ D = Globals::DropDown;
                                              
                v = $Values & ¶ ;
                                              pV = Position ( v ; D ; 1 ; 1 ) ;
                 
                                             Start = Position ( v ; ¶ ; pV ; -2 )
                                             ];
                 
                                             Middle ( v ; Start + 1 ; pV - Start -2 )
                                             ) ]

                End IF

                Thanks to Phil I was able to create it.

                Actually I see much value for this if you're not working directly in tables, but do everything from an interface table. E.g.: I have an unfiltered portal which has a search functionality (a global contains the list of record id's to show, the search sets the list of record id's). I have a slide on the layout which shows the details of one record. When clicking a portal record, the slide with the record details is shown. Now with the previous/next button I can easlity navigate through all records shown in the portal/search result.

                If the list is not stored in a value list but in a global, you only need to change the way to set the variable:

                Set Variable [$Values ; value: List(Globals::yourFieldContainingYourList) ) ]

                and the script stays the same e.g.:

                IF [ Globals::IdOfRecordToShow ≠ GetValue ( $Values ; 1 ) ]
                   Set Field [ Globals::IdOfRecordToShow ;

                                   Let ( [ D = Globals::IdOfRecordToShow;
                                              
                v = $Values & ¶ ;
                                              pV = Position ( v ; D ; 1 ; 1 ) ;
                 
                                             Start = Position ( v ; ¶ ; pV ; -2 )
                                             ];
                 
                                             Middle ( v ; Start + 1 ; pV - Start -2 )
                                             ) ]