7 Replies Latest reply on Feb 9, 2012 8:17 PM by philmodjunk

    Adding a button to create a new child record

    jared944

      Title

      Adding a button to create a new child record

      Post

      Hey everyone,

       

      I want to have a few drop down selectors connected to fields on a child table. I want to be able to select a combination of 3 or more of these selectors, creating a unique combination. I then would like to hit a button that would save these values in the child table and create a new record. I then may want to select another unique combination to save and create a new child record (and so fourth).

      Additionaly, I want a portal so I can see what records have accumulated thusfar.

      So, my question is how can I create a button to create a new child record in this situation?

      Filemaker_Create_Child_Record2.png

        • 1. Re: Adding a button to create a new child record
          jared944

          Edit:

           

          It seems that even if a create a new record manually, if I select a new combination of dropdowns it will edit the previous record, not the new one that was just created. So the button would not only have to create a new record, it would also have to associate those dropdowns with the key from the new field (?).

           

          Some background - Im trying to build an EMR and each child table would correspond to a certain anitomical location, the three dropdowns indicate the (1) severity, (2) description and (3) direction of the condition noted. One person (the parent table) could have multiple combinations of conditions in the same area (the child table).

          The portal would display a history of the conditions that were previously noted, be it today or a year ago. If nothing of value was noted, it would be empty.

           

          Thanks!

           

          Jared

          • 2. Re: Adding a button to create a new child record
            philmodjunk

            First, the basics:

            Assuming your portal relationship is:

            PatientInfo::PatientID = Conditions::PatientID

            Option 1 (what you requested)

            Define three fields with global storage and format them with your three value lists.

            Then, use this script for your button: (I'm calling the portal's table "conditions".)

            Freeze Window
            Set Variable [$PatientID ; value: PatientInfo::PatientID]
            Go to Layout [Conditions ( conditions )]
            New Record/Request
            Set Field [Conditions::Severity ; PatientInfo::gSeverity]
            Set Field [Conditions::Description ; PatientInfo::gSeverity]
            Set Field [Conditions::Direction ; PatientInfo::gDirection]
            Set Field [Conditions::PatientID ; $PatientID ]
            Go To Layout [Original layout]

            Option 2 (a simpler approach)

            In the relationship, specify "Allow Creation of records via this relationship" for Conditions table.

            Then format the severity, Description and Direction fields in the portal with your drop down lists. You can then create records directly in the portal just by selecting a value from one of the three drop down lists in the bottom blank row of the portal.

            I also suggest that you not use a different table for each anatomical location. Use the same table, but include one more field to identify the anatomical location. This should make for more flexible reporting if you keep all conditions data in a single table.

            • 3. Re: Adding a button to create a new child record
              jared944

              Yes, option 2 is much easier!

               

              The problem with having one table is that there would be multiple (and unequal) entries for each anatomical location. Unless there is some dynamic way of having multiple entries for a single field (under a single record) Im not sure its possible.

              Is there a way for the portal to be set up so that the oldest information is found at the bottom of the portal, v/s at the top? Ideally I would like to input information at the top of the portal and have it recorded on the second line, moving everything down.

               

              Thanks for the great help!

               

              Jared

              • 4. Re: Adding a button to create a new child record
                philmodjunk

                The problem with having one table is that there would be multiple (and unequal) entries for each anatomical location. Unless there is some dynamic way of having multiple entries for a single field (under a single record) Im not sure its possible.

                Each entry should be a separate record for the portal table. You can create as many or as few records for each location as you need.

                Is there a way for the portal to be set up so that the oldest information is found at the bottom of the portal...

                This is the primary reason why a developer would choose to go with option 1. You can specify a sort order for the portal that lists the newest record at the top. One simple way to do that is to define an auto-entered serial number field in the portal field. Then you specify a sort order for the portal that sorts the records in descending order on this serial number field. Then, a new record button can add a new record, but the sort order will place it at the start.

                Here's a simplified script:

                Freeze Window
                Set Variable [$PatientID ; value: PatientInfo::PatientID]
                Go to Layout [Conditions ( conditions )]
                New Record/Request
                Set Field [Conditions::PatientID ; $PatientID ]
                Go To Layout [Original layout]

                With this script, you just put the new entry button above the top of your portal. You click the button and a new blank record appears in the top row of the portal and then you select values from the drop down fields located in the portal row.

                • 5. Re: Adding a button to create a new child record
                  jared944

                  For some reason the script doesnt want to work for me. Selecting somthing new will change all of the previous records to the new record, and it seems that the foreign key isn't updating to the patient ID. Im probably doing somthing wrong but I cant seem to figure it out. 

                  A couple more questions : I would like to return to the original tab on the original record I was at when I click on the script - any ideas how to do that?

                  Eventually, I would like to create a calculated field under each anatomical area that would combine the date, severity, description and direction (IE, a calculated field that would show:  Date  &  " "  & AdnexaSeverity  & " "  & AdnexaDescription  & " "  & AdnexaLocation) and have it sort by the date.Would I have to have 2 portals to do this? One for the value inputs and one to see the records?

                  Here is my script thusfar:

                  Freeze Window

                  Set Variable [$PatientID; Value:Patient Information::__PrimaryKeyPatientID]

                  Go to Layout ["Adnexa" (Adnexa)]

                  New Record/Request

                  Set Field [Adnexa::+ForeignKeyAdnexa[$PatientID]]

                  Go to Layout [original Layout]

                   

                  Thanks for the great help!

                   

                  Jared

                  • 6. Re: Adding a button to create a new child record
                    jared944

                    One additional question to better help me understand :

                    In the first reply, a part of the scipt contains:

                    Set Field [Conditions::Severity ; PatientInfo::gSeverity]
                    Set Field [Conditions::Description ; PatientInfo::gSeverity]
                    Set Field [Conditions::Direction ; PatientInfo::gDirection]

                    What are the fields "gSeverity, gDirection" related to? Do I need to create a new key in the table "PatientInfo" that would mirror the key fields in the table "conditions"? Im guessing the "g" denoted the global field, right? Would both key fields have to be global?

                     

                    Thanks!

                     

                    Jared

                     

                    • 7. Re: Adding a button to create a new child record
                      philmodjunk

                      g is just the letter g. It confers no special property on the fields. It's just a labelling technique to help you know that the fields have global storage. Global storage is a property you can select for a field on the storage tab of field options. To open field options, find the field in Manage | Database | Fields and double click it.

                      In the original script, those three fields were the fields you wanted set up as drop down lists for selecting values before clicking the button to create the record. The later posts spell out options that make these fields unnecessary.

                      I can't quite picture what you are trying to do with your calculation combining data from multiple fields. Why do you need to combine the data like this? Usually there are other ways to do this that do not require a script. You might not need a calculation field. But I need a more detailed description.

                      For some reason the script doesnt want to work for me. Selecting somthing new will change all of the previous records to the new record, and it seems that the foreign key isn't updating to the patient ID. Im probably doing somthing wrong but I cant seem to figure it out.

                      Is this the script that doesn't work?

                      Freeze Window
                      Set Variable [$PatientID ; value: PatientInfo::PatientID]
                      Go to Layout [Conditions ( conditions )]
                      New Record/Request
                      Set Field [Conditions::PatientID ; $PatientID ]
                      Go To Layout [Original layout]

                      I don't know exactly what you did. What do you mean by "selecting something new"? When a script doesn't work, it's often helpful to enable the script debugger and data viewer (must have FileMaker advanced) and then step through the script one step at a time to see where and how the script fails to wrok as expected.