6 Replies Latest reply on May 22, 2017 2:35 PM by user1069

    Using selected text as a find criterion in a script


      Having captured selected text using


      Middle ( Get (ActiveFieldContents  ) ; Get ( ActiveSelectionStart ) ; Get ( ActiveSelectionSize ) )


      And  having set it into $Var


      I would like have a script perform a find in Table::Field using equality to $Var as the criterion


      I'm not sure what script steps to use and whether or not I can avoid manual use of a dialog box so the script does this automatically



        • 1. Re: Using selected text as a find criterion in a script

          Enter Find Mode []

          Set Field [ Table::Field; Value: $Var ]

          Perform Find []


          If your search criteria might have any special characters in it you may need to escape them. If it's just text/numeric then you're probably fine with the above.

          • 2. Re: Using selected text as a find criterion in a script

            Thank you


            I had trouble when I tried something similar. Dialog boxes kept coming up


            No special characters though.  I'll try again tomorrow

            • 3. Re: Using selected text as a find criterion in a script

              escape them or quote them.



              Enter Find Mode []

              Set Field [ Table::Field; Value: "==" & Quote ( $Var ) ]

              Perform Find []


              == specifies and exact match rather than partial string matching so don't include that unless you want an exact match. The quote function encloses the text in quotes so that characters such as @ and # are treated as actual characters and not find operators.

              • 4. Re: Using selected text as a find criterion in a script

                You can also write it like this:


                Enter Find Mode []

                Set Field [ Table::Field; Value: "==" & Quote ( $Var ) ]

                Set Error Capture [on]

                Perform Find []


                and no dialog will pop up if no records are found. You can then add an If step using Get ( FoundCount ) = 0 to detect when no records are found if you want the script to do something else when no records are found.

                • 5. Re: Using selected text as a find criterion in a script

                  I greatly appreciate the help I’ve received from the Filemaker community.  As a way of saying thanks here is what I’m trying to do, and why the usual database structure won’t work.  Hopefully the community will find this interesting.

                  Rather than be abstract I’ll start with a specific example  of the way information is actually linked together in my Hypercard Application that I’m bringing over to Filemaker.

                  Hypercard only works on PowerPC and older processors.  When Apple moved to Intel, memory management was completely different, and Apple didn’t migrate Hypercard to it.  When my last computer still running OS9 goes, my application will go with it.


                  The following is a single record (HyperCard calls them Cards) from a table (Hypercard calls them Stacks) called Xref — it contains 15,000 + such records.  I've entered all the data myself as I've read the literature, so it's pretty stripped down with just what new information the papers read provided that I wasn't familiar withy. 


                  Title: Apolipoprotein A -IV


                  # This is a protein which carries fat around in the blood. As a clinical neurologist, I dealt with vasular disease producing strokes and dementia daily, so I wanted to know as much as I could about the cause of vascular disease and what we could do about it.


                  Text:      This is a 46 kiloDalton plasma apolipoprotein made only by the small intestine during fat absorption.  Interestingly, it circulates primarily unassociated with plasma lipoproteins.  It may play a part in the assembly and intravascular metabolism of HDL (high density lipoprotein).  HGowever it is a component of intestinally derived triglyceride-rich lipoproteins.       [ Science vol. 273 pp. 966 - 968 '96 ]  Apolipoprotein A-IV activates lecithin cholesterol acyltransferase, promotes cholesterol efflux from cholesterol loaded cells and binds to liver cells.  It may play a role in reverse cholesterol transport.        [ New England J. Med. vol. 331 pp. 706 - 710 '94 ] People vary tremendously in their response to cholesterol feeding.  Most show rises in cholesterol and LDL levels, but the amount of rise varies.  This paper shows that two different alleles of apolipoprotein A-IV have different responses to the hypercholesterolemic effect of cholesterol feeding.   The most common allele has glutamine at amino acid #360, while the less common allele has histidine.  Thus the two forms of the protein have different charges at neutral pH and can easily be distinguished by electrophoresis.   1/7 of people hare heterozygotes for the two alleles while most are homozygotes for the common allele.   Heterozygotes show a much smaller elevation of cholesterol to feeding than homozygotes.  

                  Topic:  Lipids and Lipoproteins, Atherogenesis

                  # This is one of some 350 Topics — in another stack (Table).  There are 350 records here, and this card is assigned to this topic.  Each record in this table contains (among other things) a list of each of the 15,0000 cards assigned to this topic.  Other topics would be things like Alzheimer’s, Parkinsonism, or anything else I’m interested in such as astronomy, math, physics etc. etc. 

                  Buttons:  Two  Reverse Cholesterol Transport, HDL

                  # HDL stands for High Density Lipoprotein.  The first  button takes you to the Glossary (another table) which has 8,000+ records.The second button takes you to a different record in the Glossary.  The HDL glossary record has another button which takes you to the Index Table (21,000+) records.  The HDL record in index contains some 25 buttons.  Here is what just two of them do

                  The receptor button takes you to a record in Xref concerning the protein receptor for HDL — which contains 3,493 words of text — that record has 18 buttons which go to any of the 4 tables mentioned (Xref, Index, Glossary, Topics)

                  The Estrogen Effects on takes you to a record in Xref which concerns the relationship between estrogen, stroke and Alzheimer’s disease — it contains 4,725 words of text

                  By now it should be clear that I need all 4 tables available at once, and the ability to follow any button on any record to wherever it leads.  So each of the 4 tables are related to the other 3.  Each record in each table can contain multiple buttons which can go to records in any of the 4 tables (and usually do).

                  Once again, thanks for all your help — I’m sure I’m going to have more programming questions.  What help you've given so far has been invaluable.

                  • 6. Re: Using selected text as a find criterion in a script

                    I live in abstraction, so to me this sounds like a perfect application of an abstract data model. I would likely use a table of keyword entries to represent the buttons. Each entry would have tuple containing the XREF identifier, the keyword, the destination type, and the destination key. Example entries related to the "Apolipoprotein A-IV" XREF record:


                    xrefID: 22B56460-F7C8-40CA-AABE-0AB7BB1FABBD (the unique identifier for the "Apolipoprotein A-IV" record)

                    keyword: Lipids and Lipoproteins

                    destinationType: topic

                    destinationKey: Lipids and Lipoproteins


                    xrefID: 22B56460-F7C8-40CA-AABE-0AB7BB1FABBD

                    keyword: Reverse Cholesterol Transport

                    destinationType: glossary

                    destinationKey: Reverse Cholesterol Transport


                    xrefID: 22B56460-F7C8-40CA-AABE-0AB7BB1FABBD

                    keyword: HDL

                    destinationType: glossary

                    destinationKey: High density lipoprotein


                    xrefID: 22B56460-F7C8-40CA-AABE-0AB7BB1FABBD

                    keyword: ABCA1

                    destinationType: glossary

                    destinationKey: ATP-binding cassette transporter


                    xrefID: 22B56460-F7C8-40CA-AABE-0AB7BB1FABBD

                    keyword: receptor

                    destinationType: xref

                    destinationKey: HDL receptors


                    You can then create a portal showing these related records. You can use portal filters to only show certain types of records or portal sorting to group them. You can use a OnObjectEnter script trigger that you attach to the portal object; this will run your "button" script that shows the appropriate record on the appropriate view.


                    I find that the challenge with this type of thing is not the data structure so much as getting it to look and behave as you'd like. It would be great if you could highlight text and create a hyperlink within it (well... you can, but that requires more advanced Javascript skills than can be presented as a response here) but lacking that you'll have to use other ways of presenting the links for your data.