13 Replies Latest reply on Jul 23, 2015 8:08 AM by JarvisSeabolt

    Using a scrip to find the current parent record

    JarvisSeabolt

      Title

      Using a scrip to find the current parent record

      Post

      I'm new to Filemaker. I have a parent record with related portal records on a layout.  I need to make the current selection of parent records one record and I want it to be a click on the current page and the parent record being viewed be the one found record. I think a Perform Find should work but I can't figure how to tell the Perform Find to find the current record. Thanks

       

        • 1. Re: Using a scrip to find the current parent record
          SteveMartino

          1.  Why?  Why do you need to do this?  I think what you are trying to say is you have a found set of records.  But you want to change the found set of records to isolate and only show the current record?  On the same layout? The easiest, if the DB is a single user, would be thru the toolbar.  While you are on the record you want to isolate, SHOW ALL RECORDS, OMIT RECORD, SHOW OMITTED ONLY.  You could also do this with a script and a script parameter, the script parameter can be the primary key field, and the script can be, ENTER FIND MODE[ ], SET FIELD [YourTable::Primary KeyField; Get(ScriptParameter)], PERFORM FIND[ ]

          Or you can make a script, that does the show all, omit record, show omitted only, and put it on a button

           

           

           

           

           

           

          • 2. Re: Using a scrip to find the current parent record
            JarvisSeabolt

            Thanks for the reply. I have a person's name and a list of drugs in a portal view on the layout. I have a script that request a date and finds all patients the have a drug expiring on that date. If only on patient is found, (1/records in patient tableI I can use the Find Field Contents to replace all this patients portal drug records with an updated date. If two patients are found, I have to do a search to to find the patient that needs updating to keep from updating both patient's portal records. I want to select the correct patient by clicking a button.

            • 3. Re: Using a scrip to find the current parent record
              JarvisSeabolt

              The tool bar solution works perfect. Now to write the script to save 3 clicks. Thanks again

               

              • 4. Re: Using a scrip to find the current parent record
                SteveMartino

                Here's another thought

                Well that's different then your first description.  Just to clarify:

                I have a person's name and a list of drugs in a portal view on the layout

                Does that mean:

                1.  I have a person's name on the layout, and a list of drugs (related record) in the portal?

                2.  I have a person's name AND a list of drugs (both) in the portal?

                If it's number one, the next question would be, when you do a search, are you searching on the portal for a specific drug, and that search brings up all the people who have that drug expiring?  Then you go to the related records of the patients. 

                If you are replacing all the found records with the same updated date, Replace Field Contents will replace them all with the same date, or the same formula (either hard coded-August 31, 2015 or (expiration date field) + 30 )

                But you also say this:

                I can use the Find Field Contents to replace all this patients portal drug records with an updated date

                This is a little confusing because it contradicts:

                finds all patients the have a drug expiring on that date

                So you want to find a patient with a drug expiring, go to that patients record, to the portal and change all the drugs expiration date?

                If this is true, then you can do something like the following-assuming all the dates will be the same;

                Always try on Copy of Database, watch thru the Script Debugger

                Set Error Capture [On]

                Allow User Abort [Off}

                Perform your find // this will give you a found set of records with patients with expiring drugs

                If [Get(FoundCount) //Check for found records ,VERY IMPORTANT so you don't change records if you don't find any expiring drugs

                     Then a Loop

                          If [Count (DrugTable::_fkID)//check to see there are related records of drugs in the portal)

                                    Go to related records in a new window//this will bring you to a layout based on the portal of the first patient in the found set

                                    Replace field contents //select the correct field, this will replace all the field contents of the portal records of the first patient record (can be a formula

                                    Close Window //Close the window from the portal

                          End If

                          Go to Record [Next, exit after last] //Next Patient record

                     End Loop

                Else

                     Show custom Dialog [No Records Found!;//  do what you want to do here for no records found

                End If

                Now this will need some tweaking, but it's the basic outline.

                • 5. Re: Using a scrip to find the current parent record
                  JarvisSeabolt

                  The script is telling me the provided find criteria is not valid. Here is the script.  ENTER FIND MODE[ ], SET FIELD [P/W Patients::Patient ID; Get( ScriptParameter )], PERFORM FIND[ ]. I get Patient ID by double clicking from the list. I get the GET function for Specify and Function list and type in ScriptParameter. What am I doing wrong. Thanks


                  Now to your last post See screen shot
                   
                   
                  The related portal records have a run out date and The calendar Find button let me select a date that finds all patents with a drug that has the run out date entered. I will try your suggestion for second approach. Thanks
                  • 6. Re: Using a scrip to find the current parent record
                    JarvisSeabolt

                    You said:

                    Always try on Copy of Database, watch thru the Script Debugger

                    Set Error Capture [On]

                    Allow User Abort [Off}

                    Perform your find // this will give you a found set of records with patients with expiring drugs

                    If [Get(FoundCount) //Check for found records ,VERY IMPORTANT so you don't change records if you don't find any expiring drugs

                    --------

                    I have the script working to find patients with expiring drug entries. If there is more than one patient with expiring drug the user has  to decide which user to select as the advance to the correct record. I'm trying to help a friend that owns a drug store. All I need is a script that does the same action as SHOW ALL RECORDS, OMIT RECORD, SHOW OMITTED ONLY. I can't understand why the first script you suggested is giving me an error when I run it.

                    ENTER FIND MODE[ ]

                    SET FIELD [P/W Patients::Patient ID; Get( ScriptParameter )]

                    PERFORM FIND[ ]

                    Thanks for the Debug script suggestion.

                     

                     

                    • 7. Re: Using a scrip to find the current parent record
                      SteveMartino

                      If you are settin up a button or a script trigger, you first choose a script, then set up the script parameter.  You have to set up the script parameter with the proper field.  Also open up your Perform Find script step and make sure you delete anything that may be in there.

                      • 8. Re: Using a scrip to find the current parent record
                        JarvisSeabolt

                        I have been editing the perform script button called Current. I go to script manage and double click the script. I delete everything and start creating the a new script or I edit a script and hit the change button. I double click the Enter Find Mode and remove pause. I add Set Field with the parameters shown above, and add the Perform Find. Close the windows and FileMaker is happy. I run the script and it gives me a dialog saying the provided find criteria is not valid. If I change to script to just perform find and specially P/W Patients::Patient ID the enter a valid Patient ID number like 6, it works.  Thanks for the help

                         

                        • 9. Re: Using a scrip to find the current parent record
                          JarvisSeabolt

                          I open up perform script and deleted something like find records but it still don't work. I close out the windows and save. If I check perform now it is empty.  Thanks

                           

                           

                          • 10. Re: Using a scrip to find the current parent record
                            SteveMartino

                            Just to make sure you are following my instructions.  How do you call the script?  From a button, or a Trigger?  Look at my last screen shot.

                            From Button Setup, you pick the script from the list (slightly hidden)  But see at the bottom where it says 'Optional script parameter'?

                            Clicking on the Edit button on the right will open up the Specify Calculation dialog, where you put the proper script parameter.

                            Okay your way out of everything, then when you click the button to perform the script, it will carry the script parameter along

                            Also, double click your Perform Find [ ] script step and make sure there is no find criteria specified.

                            If that still doesn't work, replicate my last screenshot with one from your database

                            edit:  You can also watch this unfold with the script debugger to see if it is putting the proper data in the proper field in find mode.

                             

                            • 11. Re: Using a scrip to find the current parent record
                              JarvisSeabolt

                               

                              Sorry for the absence, I've had to work on some different projects. I call the script with a button that I created to perform script and specify script. I have several outer button call scripts working. I specify the target for the script and calculated results. If I just enter a 6 for the calculated results the script work a selects the one patient that has a patient ID of 6.  For some reason the Set Field is not passing the current record Patient ID to Perform Find. I have found a good workaround but it bothers be I can't get your script to work. Thanks

                               

                              • 12. Re: Using a scrip to find the current parent record
                                SteveMartino

                                If you are calling this script from a button, you must not be setting up the optional script parameter.

                                Take a look at this pic, then post a pic of you DB with these 3 screens showing.

                                • 13. Re: Using a scrip to find the current parent record
                                  JarvisSeabolt

                                  Duh, sorry you had to draw me a picture 6 times. Works perfect!!!