6 Replies Latest reply on Aug 17, 2015 9:48 AM by philmodjunk

    Duplicate record creation ?

    jon@thanspence.com

      Title

      Duplicate record creation ?

      Post

      I am steadily learning.... But I am finding Filemaker a little difficult to control, hopefully time will help :-)

      I have created a Layout and on the Layout have created a button which displays a Popover.

      The layout itself is linked directly to a table that holds expenditure detail. One of the fields is a field that holds a description of the 'Building' that the expenditure is associated to.

      The Building field on the layout is a list which is populated from the Building Table.

      The Building Table, has 2 fields, auto ID and the text field for the description of the Building.

      When I am on the Layout with the expense details, if I want to add a new building record, the button that I mentioned above, displays a popover and I have placed the building_name field onto the popover.

      I have then created a button on the popover called 'Done'. If you press this button, the following code is executed.

      The problem I have is that when I press the 'Done' button - it creates 2 records the actual record plus a blank record? And I don't know why.... Can anyone help where I am going wrong.... ?

      script.jpg

        • 1. Re: Duplicate record creation ?
          philmodjunk

          Am I correct that these records are shown in a portal? (You make no mention of your portal, but your script is the classic script for adding related records to a table that are typically then shown in a portal.)

          If so, you don't have two records. You have the new record plus the blank "add row" shown in a portal when the underlying relationship has the "allow creation of records via this relationship" enabled. This allows you to add records in the portal simply by entering data in a field of this blank "add row" and FileMaker copies over the needed match field values to link the new record to your current layout's record for you.

          If you are always going to use the above script to add related records, you can clear the check box for this option and the "add row" will disappear from your portal.

          • 2. Re: Duplicate record creation ?
            jon@thanspence.com

            Dear PhilModJunk

             

            I have not created a portal on the popover area. I have just placed a field object that is linked to the building table, and is displaying the building_name field. On the same popover area I have placed 2 buttons:

            A button to cancel and a button to save.

            When I press the 'save' button, the code I have screenshot on original posting is used.

            When I check the building database records using a standard table layout - I can see that 2 records have been created, a record with the text that has been input into the building_name field on the popover area and a new blank record.

            • 3. Re: Duplicate record creation ?
              philmodjunk

              The script you show cannot create more than one record, but it adds it to the current found set on the layout where it creates it. Might there have already been a blank record there before this script was run? If you run the above script 3 times, what do you get? 1 blank record and 3 new ones or 6 new records, 3 of which are blank?.

              The other thing to check is that scripts that change layouts also can trip a number of script triggers on either or both of the two layouts so there might be another script out there that is also being performed when you run the script that you've posted.

              • 4. Re: Duplicate record creation ?
                jon@thanspence.com

                Here is the Layout view......

                 

                 

                • 5. Re: Duplicate record creation ?
                  jon@thanspence.com

                  The layout view is a form view and called Expense Detail. It is associated to Expense period Table.

                  The fields within Expense Period Table are placed in the area labelled "1"

                  The area labelled "2" is a Portal and is associated with the Expenses Table". The Expenses and the Expense Period Table are related by a many to one relationship.

                  On the Portal is a field called "Building", this is populated from a drop down list which uses data from the Building Table. The field is called building_name.

                  What I am trying to do is create a new building record / name when it does not exist in the drop down list when populating the Building Name field in the Portal area.

                  I am doing this by adding the "Add Building Popover" button which displays the area Labelled "3"

                  Within this area I have added the building_name field from the Building Table and when the "Done" button is clicked it calls the script that I have posted earlier.

                  I have checked and it seems to be doing 2 things..... Creating a blank record and an actual record in the Building Table and it is also overwriting records??? It is not working correctly and I am sure it is because I am not using the objects correctly... I can't be far away but at the moment it feels it!

                  I am really new to Filemaker and I am not a coder, therefore please excuse my lack of knowledge.....

                   

                  • 6. Re: Duplicate record creation ?
                    philmodjunk

                    Your script does exactly one thing:

                    It creates a new blank record in the Building table. Nothing more. Nothing on the layout you have shown, except the value list on the building name field will change when you run this script. You'd have to check the total number of records on a layout based on the building table, then run this script and note what change occurs in the total number of records in that table.

                    If additional records are appearing in the building table, they aren't being added by this script. That's why I mentioned the possibility that the go to layout steps in the script might be tripping script triggers that perform another script that might affect the results that you see here.

                    The set field step that follows is missing the calculated result parameter needed  in order to assign a value to the building name field.

                    From what I see in the script, it should read: Set Field [Building::Building_Name ; $building_Name ]

                    It won't overwrite any records. It can't. It doesn't even modify the fields of any records directly. The only way any data in this new record can be entered into fields of this new Building record is if the field has an auto-enter field option of one type or another.