Search code examples
filemaker

Filemaker Getting Record ID from Related Value in Calculated Repeating Field


I am working on an image gallery. Horizontal portals were not an option here. I Have created a nice thumbnail grid using a vertical portal and a repeating field.

I used GetNth to grab the images.

GetNthRecord ( Extend(FARMS_PHOTOS 2::IMAGE) ; Get ( CalculationRepetitionNumber ) )

I am having trouble figuring out how to get the image ID for each image into a script. I want this to function like a traditional image gallery. So the idea is to now attach a script to the repeating field that will grab the Image ID so that it can be manipulated.

Any suggestions?


Solution

  • Here are two approaches to this problem.

    Option 1. Use a Script Parameter to tell the script what repeat is being clicked.

    You will need break up the repeating field into individual field objects for each repeat. You can do this by setting the "show repeat" option on the "Data" of the inspector. When you do that each field object and therefor repeat can be it's own button. Each button can get its own parameter. So you assign a parameter of 1 to the field object for repeat 1 and so on. Now that you have a script parameter for each repeat you can use a variation of the GetNthRecord calc you showed above to get the ID

    This is a bit tedious to setup but it behaves well.

    Option 2. Use an ObjectEnter Script Trigger

    If you don't want to break up the repeating field object you can instead attach an object script trigger to the repeating field. Pass in "Get ( ActiveRepetitionNumber )" as the script parameter. When the user clicks into the field the script will fire and receive the repetition number as the Script Parameter. Then proceed with your GetNthRecord calc.

    This is easier to setup. But the event that triggers the script is a Mouse Down event. That's a bit weird. Buttons should fire on Mouse Up, not Mouse Down. Also you will have to tweak the styles so that it doesn't look weird when the user enters into that field. But it works