5 Replies Latest reply on May 22, 2017 2:18 AM by benalgrain

    Looking for help using portal data in a scripted search

    benalgrain

      Hi All,

       

      I was wondering if anyone could help me out with a little problem I have run into.

      Background: I have 1 table (ArtistInfo) in which is stored all the info related to the actors (each actor having their own record in that table). There are various fields in this table containing info like Age, Gender and Race.

       

      I then have another table (JobInfo) in which is stored all the info relating to a specific job, and have created a Character table linked to this in which the various characters are stored. On the "Job" layout, I have a portal into the Character table and can create new character records in the Character table through the portal. Each Character record has fields for 'Race", "Gender", "Age from", and "Age to". The portal displays these fields and what I am trying to achieve is a button in the portal which when clicked will take the criteria in portal fields and use them as the search criteria in the Artist Table, thereby giving me a result of the actor's records that match the characters' criteria. I have scripted as follows for the button:

       

      New Window [ Style: Document ; Name: "ARTIST SEARCH" ; Height: 700 ; Width: 1050 ]

      Go to Layout [ "Artist" (ArtistInfo) ]

      Enter Find Mode [Pause: Off]

      Go to Field [ ArtistInfo::Sex ]

      Set Field [ ArtistInfo::Sex ; Characters::CharacterSex ]

      Go to Field [ ArtistInfo::Age ]

      Set Field [ ArtistInfo::Age ; Characters::CharacterAgeFrom & ".." & Characters::CharacterAgeTo ]

      Go to Field [ ArtistInfo::Race ]

      Set Field [ ArtistInfo::Race ; Characters::CharacterRace ]

      Go to Field [ ArtistInfo::Status ]

      Set Field [ ArtistInfo:: Status ; "Active" ]

      Perform Find

       

      I hope all of this makes sense, I'm figuring things out as I go along, and it sometimes takes months for me to realize a stupid little mistake that I made along the way and can't really afford the time. Thanks in advance for the help!

       

      Ben

        • 1. Re: Looking for help using portal data in a scripted search
          philmodjunk

          You do not need to use go to field to put the focus in the field before using set field to enter data (or in this case find criteria).

           

          When in find mode, all non-global fields are empty. Thus, a step like:

          Set Field [ ArtistInfo::Sex ; Characters::CharacterSex ]

           

          Sets Sex to an empty value unless CharacterSex is a global field. It seems unlikely that this is the case.

           

          It would seem that you need the following relationships, do you have them?

           

          JobInfo----<Characters>-------ArtistInfo

           

          JobInfo::__pkJobInfoID = Characters::_fkJobInfoID

          ArtistInfo::__pkArtistInfoID = Characters::_fkArtistInfoID

           

          Characters is then a join table between JobInfo and ArtistInfo to facilitate a many to many relationship.

           

          In  a portal to Characters on the JobInfo layout, you can format _fkArtistInfo with a value list of ArtistInfo ID's and names in order to select an artist. I realize that you want a search capability, but am pointing out a simpler approach that can be the basis of more sophisticated selection techniques.

           

          And your approach with a scripted find can work, if you specify your criteria into global fields while in Browse mode before running the script to find a record in order to get the ArtistInfo ID to use to link the character's record to an artist.

           

          Resources:

          Scripted Find Examples

          Other methods for finding and linking info:

          Adventures in FileMaking #1--conditional value lists

          Adventures in FileMaking #2--enhanced value selection

          • 2. Re: Looking for help using portal data in a scripted search
            bigtom

            Lots of ways this can be done. I have found that dealing with portals and scripting it is often good to use Go To Object.

            • 3. Re: Looking for help using portal data in a scripted search
              philmodjunk

              It is true that you sometimes need go to object to put the focus on the correct portal, but that's not what this find script appears to be doing here as the script directly searches the table on which the portal is based, it does not actually interact with the portal and you certainly do not need go to field just before every set field. Not only is this unnecessary, can produce "brittle code" as putting the focus into every field can trip script triggers--not only any that might be present now, but at some time in the future, someone might add a new trigger and then your script performs differently than it did before--and this is completely unnecessary in the search script being discussed here.

               

              PS. and I would use one method or another to select the artist first, then create the record in the Characters table--an assumption that I may not have made as clear as I should have in my last post.

              • 4. Re: Looking for help using portal data in a scripted search
                BruceRobertson

                As mentioned by others, you will need to capture the criteria before you leave the portal row.

                Once you have left the portal, gone to another layout, and entered find mode, FileMaker has no connection to where you started.

                To do what you asked for, I'd suggest mods to your script, like this:

                 

                Set Variable [ $sex; Characters::CharacterSex ]

                Set Variable [ $ageSpan; Characters::CharacterAgeFrom & ".." & Characters::CharacterAgeTo ]

                Set Variable [ $race; Characters::CharacterRace ]

                New Window [ Style: Document ; Name: "ARTIST SEARCH" ; Height: 700 ; Width: 1050 ]

                Go to Layout [ "Artist" (ArtistInfo) ]

                Enter Find Mode [Pause: Off]

                Set Field [ ArtistInfo::Sex ; $sex ]

                Set Field [ ArtistInfo::Age ; $ageSpan ]

                Set Field [ ArtistInfo::Race ; $race ]

                Set Field [ ArtistInfo:: Status ; "Active" ]

                Set Error Capture [ On ]

                Perform Find

                1 of 1 people found this helpful
                • 5. Re: Looking for help using portal data in a scripted search
                  benalgrain

                  Thank you so much for your quick replies and really helpful answers. The script as laid out works perfectly, and I have learnt and understand what I was doing wrong.