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::__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.
Other methods for finding and linking info:
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.
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.
1 of 1 people found this helpful
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 ]
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.