4 Replies Latest reply on Mar 4, 2013 5:12 PM by JorgeFernandez

    Create related record script

    JorgeFernandez

      Title

      Create related record script

      Post

           Hi everyone.

           I´m working on a script to create a new related record but "new record" password protected. And you see, it´s working but only when the master record alredy have a related record on the second table, but no when creating a new master record having no related records. This is my script:

            

           Tables:

           General Data::Id=SecondaryData::SDId

           Global

            

           Set Field [Global::Sign;""]

           Show Custom Dialog ["Password"; "Tupe your password"; Global::Sign]

           If [Get (LastMessageChoice ) = 2)

             Exit Script []

           Else

              If [Global::Sign ≠ ********]

                 Show Custom Dialog ["Invalid"; "This is password protected"]

              Else

                If [SecondaryData::Date = 0]

                    Insert Current Date [SecondaryData]

                 Else

                    Go to Field [GeneralData::LastName]

                    Show Custom Dialog ["Out of date"; "This record is not editable anymore"]

                    Exit Script []

                 End If

              End If

           Enf If

            

            

           As I said, It works great with a Master Record with existing related records, but no when creating a new master record.

            

           I´ve being trying to create a script for a new master record with many ways to create a related record at the time, but no sucess...

            

           Any Ideas??

            

           Thanks for your reading.

        • 1. Re: Create related record script
          philmodjunk

               Your script will only create a new record in SecondaryData if a related record does not already exist., but only if "allow creation of records via this relationship" is enabled for SecondaryData in the relationship linking these two tables.

               PS: I try to never use script steps that start with "insert..." if I can use Set field to get the same result. Insert steps fail if the referenced field is not present on the current layout with access to the field permitted in field behavior settings. Set Field does not have these limitations.

               Set Field [ SecondaryData::DateField ; Get ( CurrentDate ) ]

               can take the place of Insert Current Date.

          • 2. Re: Create related record script
            JorgeFernandez

                 Ok, thanks for the tip using Set Field

                  

                 About the creation of the record, I alredy have "allow creation of records" in the relationship.

                  

                 The problem is that if I have some records like:

                 Master Record ID: 100

                      Related Records on Secondary Data for ID "100": 235, 279, 520

                  

                 If I´m on the layout in record 100, my script works !

                 But If I create a "New Master Record", the script won't work, only if I go to another record and go back to the "New Master Record" and now this work perfect.

                  

                 The "thing" that is not working is the password typing, no matter what I type, nothing happens!! It will not show ["Invalid"; "This is password protected"] or something.

                 I have to go to another record and go back to the new record to get it work.

                  

                 Where is the bug??

            • 3. Re: Create related record script
              philmodjunk

                   What auto-enter settings do you have for "master record ID"? It sounds like you are either manually entering this value or it is an auto-entered serial number with the "on commit" option specified. Leaving the record and returning commits the record. So does clicking the background of the layout.

                   

                        The "thing" that is not working is the password typing, no matter what I type, nothing happens!! It will not show

                   If this is FIlemaker 12, make sure that button one in SHow Custom dialog is specified to commit the data entered into the input field.

                    

              • 4. Re: Create related record script
                JorgeFernandez

                     Ok, I do have an auto-entered serial number for Master Record.

                      

                      

                     With this info I could find the bug!! Something between allow creating records in tables Master and Global was not active.

                      

                     Thanks a lot!!