8 Replies Latest reply on Feb 3, 2016 4:35 PM by davidhead

    Portal - Adding multiple images


      I am setting up a database with contacts (FMpro13). For each contact I need to be able to insert 1 to 50 images.

      Basically I have a file with 2 tables.

      Table 1 is Contacts with 2 fields (Name and a unique ID field)

      Table 2 is ContactPhotos with 2 fields (a Container field for the Photo and a ID field)

      I have set up a relation between table 1 and table 2 through the ID fields.

      In the layout of table 1 I have a portal showing all image related to this contact.


      Now my first question is if  there is a way I can import 50 images at once to a contact? Preferably by dragging.

      For the moment I can only add them one by one.


      Second question is if it would be better store the photos in a separate filemaker file.


      Thanks for any help because I am quite ne to FM

        • 1. Re: Portal - Adding multiple images

          Q1: Yes, you can import multiple images from a folder.


          So if you have all the images for a contact arranged in a folder, you can script the process for the user to select the folder (Get Directory script step) and then import all images from that folder. The script could then associate all the imported image records with the contact record.


          Q2: No, initially there is probably no reason to store photos in a separate file. However, you may consider external file storage for the container. Have a look at Storage options for the container field (Store container data externally).

          • 2. Re: Portal - Adding multiple images

            Thank you David for your input.

            I tried to do this manually first. (File>Import>Folder)

            Problem is I  import the images to the container field but then they are not related to any contact.

            Am I missing a field in Table 1 for this?

            • 3. Re: Portal - Adding multiple images

              After importing, you would need to set the foreign key to link those new records back to the contact. When doing this manually, you would probably use a Records > Replace Field Contents…


              If you scripted this, the pseudocode would look like:


              // Starting on a Contact record

              Set variable to the primary key of the contact

              Go to the images layout

              Get the directory of the images folder required

              Import images from the folder

              Replace field contents to set field for the foreign key (contact) using the variable

              Go back to the original layout

              • 4. Re: Portal - Adding multiple images

                This will be my first script. I will have a try at it tonight...

                • 5. Re: Portal - Adding multiple images

                  I got it working after some trial and error. Thank you for pointing me in the wright direction.


                  I now have an additional question.

                  I have not specified a directory which contains the images.

                  So the user has to browse trough the entire computer.

                  Would it be possible to open the browse window to a specific directory and let the user select a subdirectory? Additionally can I use that directory name for the name field in my contact record?

                  • 6. Re: Portal - Adding multiple images

                    The Get Directory script step allows you to define a default directory (where the search starts).


                    You will have to specify the whole file path or use something like Get ( DesktopPath ). And of course we are assuming that the directory in question will exist on the user's computer.


                    I don't quite understand what you mean by "Additionally can I use that directory name for the name field in my contact record?". If you mean can there be a field in the contact record that specifies a file path to their directory, then yes you can. And you could use that field value as the default file path. Or I suppose you could also use that to set the variable and automatically import from there. You would need some error trapping in there for the case where the file path does not exist.

                    • 7. Re: Portal - Adding multiple images

                      Hi David,

                      I think I am doing something wrong.

                      I tried using the function Get(FilePath) then the script imports the images in this folder but I don't get  a dialog to let the user select a subdirectory.

                      I also tried Get(DesktopPath) but then the script seems to assign all previous image imports to this record.

                      Here is the script I used, am I missing something?


                      For the second question:

                      I have a directory d:/models which contains subdirectories named for example Anna, Tim, Louise

                      These directories with the names contain the persons photos.

                      I would like the script to store these directory names in my field for the contacts name upon import of the images.

                      This way the user does not have to key in the contacts name in filemaker, but gets it automatically upon import of the images.

                      • 8. Re: Portal - Adding multiple images

                        OK, first, please ignore all reference to the Get Directory script step. I see in your first post (and from your script screenshot) that you are using FileMaker Pro 13. The Get Directory script step is a FileMaker Pro 14 new feature. Could be a reason to upgrade?


                        Where you are setting the variable in the third line, you would only need: "filewin:/D:/models/"


                        To direct the import to a specific folder for a model, you could use:  "filewin:/D:/models/" & MODELS::subdirectoryField

                        But you would need to set that before you leave the layout, so move the third script step up.


                        You are looping through the records to set the foreign key. You can do this for the imported found set in one step using the Replace Field Contents script step.