Search code examples
filemaker

Filemaker Using a Repeating Field in A Portal to Display Related Records


I am trying to modify a calendar module I use regularly and make it an image gallery. I have a field in "Calendar Display Rows" called "display_images". The display images field is a repeating numeric field that generates a number grid ([7] repetitions).

I have a repeating calculation field in "Calendar Display Rows" called "show images" ([7] repetitions) that is an unstored container field calculation that points at the "image" field in the table "Images".

Match fields are as follows:

Calendar Display Rows : display_images = Images : image number

How can I get the images in the "Images" table that have the matching image number to display dynamically in the repeating field "show images" according the matching number.

Note that I am trying to modify a calendar module because I want to resize the grid cleanly for a full screen appearance. Horizontal portals will not work. This is a vertical portal with a repeating field.


Solution

  • The Basics:

    Your relationship:

    Calendar Display Rows::display_images = Images::image number
    

    will, from a layout showing Calendar Display Rows, find all the images with an image number matching the value in any of the repetitions of display_images. For instance, if display_images[1] = 1 and display_images[2] = 2, you'll get images 1 and 2 through the relationship in whatever sort order is established for the relationship.

    Presuming that the repetitions of display_images are populated in the same order as your relationship's sort order, and that the only blank repetitions you have are at the highest end of the repetitions of the field (1, 2, 3, [blank] is okay, but 1, [blank], 3, 4 is not), you could use the following calculation for Calendar Display Rows::show images:

    GetNthRecord (
       Extend ( Images::image ) ;
       Get ( CalculationRepetitionNumber )
    )
    

    In the above, GetNthRecord gets the nth record, by the sort order, of the related records in Images. Extend allows the related image to be used by any of the repetitions in the repeating show images field and Get ( CalculationRepetitionNumber ) tells FileMaker that repetition 1 gets value 1, repetition 2 gets value 2, etc.

    More Advanced:

    The assumptions above (matching sort order, no blank fields in the middle) would probably work for a calendar, but may not work for an image gallery. It's entirely possible that you'd need something that allowed for blank fields or mismatched sort order.

    For that, a custom function (if you have FileMaker Advanced) may be in order. The function could repeat through the found Images records and test that display_images[i] matches image number.

    Find Proper Image Custom Function:

    Let (
          targetImageIndex = GetRepetition ( Calendar Display Rows::display_images ; forRepetition )
    ;
          Case (
               IsEmpty ( targetImageIndex ) ; "" ;
               workingRecord > Count ( Images::image number ) ; "" ;
               targetImageIndex = GetNthRecord ( Extend ( Images::image number ) ; workingRecord ) ; GetNthRecord ( Extend ( Images::image ) ; workingRecord ) ;
               Find Proper Image ( forRepetition ; workingRecord + 1 )
          )
    )
    

    Then the code in the show images calculation field would be:

    Find Proper Image ( Get ( CalculationRepetitionNumber ) ; 1 )