12 Replies Latest reply on Jul 17, 2014 8:50 AM by philmodjunk

    How to go to the next object in a layout using script trigger

    AswinSankarapillai

      Title

      How to go to the next object in a layout using script trigger

      Post

           Hello All,

               I am trying to add multiple address of a user into the layout.  In the original layout, I am trying to fill some information of a individual user which has address field through a portal. I created a search button, which takes user for searching an existing address in the database and insert the value back into the original layout. I did succeeded implementing it, Now the challenge is to store multiple address, If I search again for an existing address it replaces the existing address which I searched already, instead of adding value to the new object in the layout. I need to find a way to determine if the object 1 is empty or not, if it is empty it should insert the value, if not it should go for the next object and insert it.

            

           Thanks,

           Aswin Shnakar

            

            

        • 1. Re: How to go to the next object in a layout using script trigger
          philmodjunk

               Will multiple individuals have the same address in this system?

               Or will any given address record only link to a single record in the parent table?

          • 2. Re: How to go to the next object in a layout using script trigger
            AswinSankarapillai

                 As per the current design multiple individuals can have same address in the system.

            • 3. Re: How to go to the next object in a layout using script trigger
              AswinSankarapillai

                   Just added few snap shots on what I am looking for, I thought I can implement this change using the script by having a condition, As I am a newbee I am not sure how exactly or what kind of syntax I can use to get my work done. If possible please help me.

                    

                   I got a script which add the field into the new layout but need to find a way to insert  the second search value into the 2nd row of the portal. Suggestions would Help.

                    

                   Thanks

                   Aswin Shankar

              • 4. Re: How to go to the next object in a layout using script trigger
                philmodjunk

                     If one person can have multiple addresses and the same address can be linked to multiple people, you have a many to many relationship and need a join table to manage that.

                     Start with these relationships:

                     Persons-----<Person_Address>-----Addresses

                     Persons::__pkPersonID = Person_Address::_fkPersonID
                     Addresses::__pkAddressID = Person_Address::_fkAddressID

                     You can place a portal to Person_Address on the Persons layout to list and select  Addresses records for each given Persons record. Fields from Addresses can be included in the Portal to show additional info about each selected Addresses record and the _fkAddressID field can be set up with a value list for selecting Addresses records by their ID field.

                     So your search script for finding an address, should create a record in Person_Address that links the found address to the current Person record.

                • 5. Re: How to go to the next object in a layout using script trigger
                  AswinSankarapillai

                       OK, let me try on that. Thanks for your suggestion. 

                        

                       Thanks,

                       Aswin Shankar

                  • 6. Re: How to go to the next object in a layout using script trigger
                    AswinSankarapillai

                         Still I have the same issue, I crated the relationship as you can see in the attachment.  I am not sure what exactly needs to modified to get this working. 

                         I have a portal which is linked to address table, Is it possible to Add the second address in the portal through a script ?

                          

                         Thanks,

                         Aswin Shankar

                    • 7. Re: How to go to the next object in a layout using script trigger
                      philmodjunk

                           Yes, it is possible, but why do you need the script when you can select an address by formatting the Individual_Address::AddressID field with a value list of addresses?

                           Even if a script is necessary (as it might well be), I'd get that first option working as a test to show that all the necessary details are in place.

                           To do this, you'd

                           a) enable "allow creation of records via this relationship" for Individual_Address in the Individuals to Individual_Address relationship.

                           b) put a portal to Individual_Address on your Individuals layout.

                           c) format Individual_Address::AddressID in this portal as either a drop down list or pop up menu using a value list that specifies AddressID from Addresses as the first field and a text field that uses an auto-enter calculation to combine the values of many of your address fields to provide an  address entry that you can recognize when selecting addresses from this value list.

                           Once you can see this working, here's a scripted option:

                           The user would enter/select data in one or more global fields while in Browse mode. These fields can be on the Individuals layout, inside a popover or they can be popped up in a new modal window. A "find" button is then clicked that performs a find on the Addresses layout via script similar to those found here: Scripted Find Examples

                           Before doing that, the script would first copy the current IndividualID to a variable.

                           The script would use Get (FoundCount) to count the number of records found. If no records are found, it returns the user to the original layout and displays an error message that no matching addresses were found. If one record is found, that record's AddressID is copied to a variable. If multiple matching records are found, they are displayed for the user in a list. This can be a list popped up in a floating window or the system can just change layouts to a list view layout listing these found records. The list displays full info on each matching address and you can click a button in the boy of the list view to select a given address record. That button also copies the AddressID to the same variable as mentioned previously.

                           At this point, you have the needed AddressID and the needed IndividualID in variables. And your script can go to a layout based on the Individual_Address table, create a new record and use set field steps to copy over the two IDs into their corresponding fields before returning to the original user.

                      • 8. Re: How to go to the next object in a layout using script trigger
                        AswinSankarapillai

                             Thanks again for your response, I have already implemented the steps which you have mentioned in the first phase. Now I am working on the second phase on creating the script, before proceeding i have a question. On your thread, you have mentioned that I need to create a global storage. Should I create a new field as a global storage or can I use the existing one from the table. I believe if I use the existing one, I have to loose my data. Please correct me if I am wrong, as I am still relatively new with File Maker. 

                              

                             Thanks,

                             Aswin Shankar

                              

                        • 9. Re: How to go to the next object in a layout using script trigger
                          AswinSankarapillai

                               This is the script which I am using now, 

                                

                               Set Variable{$AddressID;Value:${Address(Table Occurance)};;AddressID]
                               Go to Layout ["Individual Profile" (Individuals)]
                               Set Field [Individual_Address::AddressID; $AddressID] 
                                
                               The script works fine, As soon as the results pops up, I have to select the address ID so that it goes back to the original window and insert the record in the portal. But if I have to add one more Address into the portal and again if I perform a search, it get updated deleting the old value, instead of updating into the second row of the portal.  Please have a look at my screen shot. 
                                
                               Thanks,
                               Aswin Shankar
                          • 10. Re: How to go to the next object in a layout using script trigger
                            philmodjunk

                                 That script clearly does not do the whole task. I must assume that you are performing a find (manually?) separate from this script.

                                 That script worked before you added a join table. It now needs to be modified to create a new record in the join table and use IDs from both an address and an Individual to link it to the correct records in these two tables.

                            • 11. Re: How to go to the next object in a layout using script trigger
                              AswinSankarapillai

                                   Sorry for the confusion again, the join table existed well before, I created this thread and you are right, I am using manual search find in the first place and then let user to select the address id which takes back to the original layout to insert the record.

                                    

                                   Thanks,

                                   Asiwn Shankar

                              • 12. Re: How to go to the next object in a layout using script trigger
                                philmodjunk

                                     But your script does not create new records in the join table and link them properly so I do not see how this ever worked with your join table.

                                     Here is one way to do that:

                                     Add an OnRecordLoad trigger on your Individuals layout that performs this script:

                                     Set Variable [$$IndividualID ; value: Individuals::IndividualID ]

                                     Then your script performed after finding an address record on the addresses layout would do this:

                                     Set Variable [$AddressID ; value: Addresses::AddressID ]
                                     Go to Layout [ "Individual_Address" (Individual_Address) ]
                                     New Record/Request
                                     Set Field [ Individual_Address::IndividualID ; $$IndividualID]
                                     Set Field [Individual_Address::AddressID ; $AddressID ]
                                     Go to Layout ["Individuals" (Individuals) ]

                                     This method assumes that you will always start from the individuals layout before changing over to addresses and finding an address record. Without that first step, the OnRecordLoad trigger isn't tripped and $$IndividualID never gets the needed value.

                                     Note: an auto-enter calculation can auto-enter the value of $$IndividualID into the Individual_Address::IndividualID field and then the script does not need the fist Set Field step.