Jump to content

Problem Implementing a Dynamic Find Using a Script Trigger (FMP 12)

This topic is 2942 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I am attempting to de-bug a dynamic sorting routine in FMP 12 Pro that dynamically sorts a list of names when letters are typed into a search field. This is based on the "Spotlight Search" template created by David Graham in 2009. http://bittailor.com. This solution uses a single table ("Contacts") and 2 Table Occurrences - "Contacts" and "Contacts_Filtered" which are related by the Search_Field in "Contacts" equalling the Search_Index in "Contacts_Filtered.


Search_Field is a global text field

Search_Index is a calculated text field using the custom function "ExplodeToMultiKey" which generates an exploded set of data from the entered text (e.g. Thomas becomes T, Th, Tho, Thom, Thoma, Thomas).


The results are shown via a portal on a layout based on the "Contacts" table which displays data from the "Contacts_Filtered" table. In the Spotlight Search Template, there is a script that uses a second layout to simulate the initial layout expanding to show the data as it is found. In my solution that technique is not required. Instead, the display layout shows all of the people in the database and narrows as data is entered into the Search_Field. 


To test this technique in my solution, I updated the script to set a global text field (called gTest) to the value GetCurrentLayoutObject before completing the rest of the script. The script (as modified) is included here for ease of reference.


Set Variable [$currentObject; Value: Get ( ActiveLayoutObjectName ) ]

Set Field [Contacts::gTest; $currentObject ]

Commit Records / Requests [ ]

Go To Object [ Object Name: $currentObject ]

Set Selection [ Start Position: Length ( Get ( ActiveFieldContents ) ) +1 ]


The purpose of the script is to update the layout contents but keep the user in the field "Search_Field" so that they can type additional letters, delete something already typed etc… Translating this script to my solution, however, this functionality doesn't work. For some reason the script is not setting the variable $currentObject to the value of Get ( ActiveLayoutObjectName ) - and I can't figure out why not. The test modification to the script works flawlessly in the Spotlight Search template file - but not in my solution. To test it, I included the gTest field in the header portion of the layout in both files. In the Spotlight Search template, the field updates to the current object name when data is entered into the field with the script trigger. In my solution it does not. The result is that once you type a single letter in the Search_Field it works, but typing a second letter (or deleting) gives you an error message that you need to select a field. This is proving maddening - so any thoughts are very much appreciated.

Link to comment
Share on other sites

Just as a sanity check: you did gave the entry field an object name?


(I have a similar script stored away as a  template, and when implementing it in a new file, I kept forgetting to assign a name to the field; that's why I added a comment to do it. Proved to be helpful …)

  • Like 1
Link to comment
Share on other sites

OMG! I'm an idiot. When I copied the database to make the test script revisions I absolutely did forget to name the field in the test layout. Thanks! Although I must now go subject myself to 20 lashes with a wet JCL reference book! Sometimes it is the simplest things. Thanks again. The comment has now been added, too.

Link to comment
Share on other sites

This topic is 2942 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.