5 Replies Latest reply on May 27, 2014 10:00 PM by robwoof

    if then statements controlling an image in a container

    bbringardner

      I am interested in controlling an image in a container with an If Statement, but am having trouble figuring out how to do it.

       

      My use case is that I would like a status field to control the icon displayed. So if the status field is "New", "Submitted", "Rejected", etc then a certain image would diplay for that record.

       

      I am new to FMP and am running File Maker 12, and any help would be greatly appreciated.

       


      Thanks,

      Ben

        • 1. Re: if then statements controlling an image in a container
          robwoof

          Hi Ben,

           

          Welcome to the FIleMaker world!

           

          To have a Container controlled by the content of another field, the Container needs to be a Calculation field with result type "Container" (in the Specify Calculation dialog that opens when you create a Calculation field, on the bottom-left there is a "Calculation Result is:" drop-down menu - choose "Container").

           

          The you need to have the various different images stored in container field(s) somewhere else. This is one situation where a Repeating Container field might be useful: create a Container field with one repetition for each different status image. Your calculation might then look something like:

           

          StatusImage =

           

          Case ( StatusField = "New" ;

                            GetRepetition ( StatusImages ; 1 ) ;

                      StatusField = "Submitted" ;

                            GetRepetition ( StatusImages ; 2 ) ;

                      StatusField = "Rejected" ;

                            GetRepetition ( StatusImages ; 3 ) ;

                            GetRepetition ( StatusImages ; 4) )

           

          In this example the StatusImages field would need to be in the same table, and it would need to be a Global field as well. Setting a field as Global and/or Repeating is done on the Storage tab in field options.

           

          If this type of thing might be required in more than one table, you could put the image storage field(s) in a separate table and link to them using a Cartesian relationship (the "x" option in the Define Relationship dialog in the Relationships Graph). Then the calculation would look something like:

           

          Case ( StatusField = "New" ;

                            GetRepetition ( ConfigTable::StatusImages ; 1 ) ;

                     StatusField = "Submitted" ;

                            GetRepetition ( ConfigTable::StatusImages ; 2 ) ;

                     StatusField = "Rejected" ;

                            GetRepetition ( ConfigTable::StatusImages ; 3 ) ;

                            GetRepetition ( ConfigTable::StatusImages ; 4) )

           

          What you want to do is very possible. I hope I have explained things sufficiently clearly for you.

           

          Cheers,

          Rob

          1 of 1 people found this helpful
          • 2. Re: if then statements controlling an image in a container
            beverly

            While these methods are ok and I've used them...

             

            If you have sufficient # of images & related states then relationship is what you need, only calculated field is not necessary. Simply show the related image field on the layout. Change the status (which is the key field in the match) and the image changes. No repeating field, no muss no fuss.

             

            Do NOT allow entry into this related field, just display it.

             

            If you need a copy of the image and not simply display, then use the relationship to LOOKUP the image into a container field. Change the status and it should relookup for the container field.

             

            -- sent from my iPhone4 --

            Beverly Voth

            --

            • 3. Re: if then statements controlling an image in a container
              erolst

              Case ( StatusField = "New" ;

                                GetRepetition ( ConfigTable::StatusImages ; 1 ) ;

                         StatusField = "Submitted" ;

                                GetRepetition ( ConfigTable::StatusImages ; 2 ) ;

                         StatusField = "Rejected" ;

                                GetRepetition ( ConfigTable::StatusImages ; 3 ) ;

                                GetRepetition ( ConfigTable::StatusImages ; 4) )

               

              Let() me suggest …

               

              Let ( [

                ~s = StatusField ;

                ~r = Case (

                  ~s = "New" ; 1 ;

                  ~s = "Submitted" ; 2 ;

                  ~s = "Rejected" ; 3 ;

                   4

                 )

                 ] ;

                ConfigTable::StatusImages [ ~r ]

              )

               

              Or as a one-liner if one had a “GetIndexFor()” CF …

               

              The use of a status table with a code plus a foreign status key would condense this into:

               

              ConfigTable::StatusImages [ fk_statusID ]

               

              Even simpler – since using the correct structure – is of course what Beverly suggested: let each status know its image. I.e. define a relationship like

               

              YourMaintable::fk_statusID = StatusTable::pk_statusID

               

              To be able to select a status, format fk_statusID with a value list like 1st: StatusTable::pk_statusID, 2nd: StatusTable::status, Show 2nd only

               

              Now simply display StatusTable::image on the layout.

              1 of 1 people found this helpful
              • 4. Re: if then statements controlling an image in a container
                bbringardner

                I ended up doing what Beverly said first since it appeared to be the simplest and it worked.  I setup a separate table (status) with two fields (status, statusImage) and related them to my main table. 

                 

                One question about performance.  I am interested in keeping my file sizes reasonable small since I am targeting mobile users and I was wondering if by doing this I will be referencing a single image multiple times in the database or if the database replicates the image everytime it is used in the related table, thus increasing file size?

                 

                 

                Being able to leverage this functionality is very helpful, thanks for the help!

                Ben

                • 5. Re: if then statements controlling an image in a container
                  robwoof

                  Beverly's solution is very elegant and easily extensible, and had never occurred to me - it's going into my toolbox.

                   

                  If you are doing it in any of the ways suggested, you only have one copy of each image stored (either in the file or externally). Each calculation or relationship that references an image only points to the image - it does not copy it.

                   

                  So you are referencing a single image, not replicating it multple times.

                   

                  Cheers,

                  Rob