14 Replies Latest reply on May 2, 2013 10:47 AM by philmodjunk

    spent hours dont understand help

    moogie

      Title

      spent hours dont understand help

      Post

           fm 12   trying to make a new record in another file what is wrong

           set error

           go to layout

           show all records

           enter find mode

           perform find

           loop

              replace field contents

              open file  (other file layout)

              new record/request

              set field

              go to record next last

           end loop

           go to layout

           enter browse

           show all records

           eit script

            

           script makes record in original layout  not in the other file layout??

        • 1. Re: spent hours dont understand help
          philmodjunk

               Your script is short on details and are you creating a new record in another FILE or just another TABLE? The two terms are not interchangeable.

               Why do you need a loop and why are you using replace field contents?

               This script example will create another record in a another table, but might not work if the table is in a different file:

               Go to layout ["Layout Name Here" (Table occurrence for table Here) ]
               new Record/Request

               That's all you need to do what you describe so long as the table specified in Go to Layout is the table where you want to create the new record. But often, such a method is used to create a new record that is linked by a relationship to the original record in the first table. So if you have this relationship:

               Table1-----<Table2

               Table1::__pkTable1ID = Table2::_fkTable1ID

               then the script might look like this:

               #Script is performed on layout for Table1.
               Set Variable [$ID ; value: Table1::__pkTable1ID ]
               Go to Layout ["Table2" (Table2) ]
               New Record/Request
               Set Field [Table2::_fkTable1ID ; $ID ]

               For an explanation of the notation that I am using, see the first post of: Common Forum Relationship and Field Notations Explained

               To post a script to the forum:

                 
          1.           You can upload a screen shot of your script by using the Upload an Image controls located just below Post A Answer.
          2.      
          3.           You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here. (If you use this option, please insert a few carriage returns as needed to keep each script step on a separate line.)
          4.      
          5.           If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
          6.      
          7.           If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format.
          • 2. Re: spent hours dont understand help
            moogie

                 mr junk  -  want to create a record in another file  -  use replace field contents so when i run script again, the record i replaced field contents, is not included another time   -  already have relationship between 2 files  -   please advise if something you suggested above relates to my confusion tks  

            • 3. Re: spent hours dont understand help
              philmodjunk

                   Do not use replace field contents. It has a different purpose that will be catastrophic for your data in this context.

                   The script will work with data in another file given that you have defined a relationship linking the two. That indicates that you have a table occurrence in your first file that references the table in the other file. You just need to create a layout based on that table occurrence if you have not already done so. To keep from creating a record in table 2 a second time for the same record in table 1, use one of these variations:

                   Set Field [Table2::_fkTable1ID ; Table1::__pkTable1ID ] ---> no layout to table 2 is needed, but "allow creation of records via this relationship" must be enabled for Table2 in your relationship.

                   OR:

                   If [ IsEmpty ( Table2::_fkTable1ID ) // no related record exists ]
                     Set Variable [$ID ; value: Table1::__pkTable1ID ]
                     Go to Layout ["Table2" (Table2) ]
                     New Record/Request
                     Set Field [Table2::_fkTable1ID ; $ID ]
                   End If

                   With the second option, you do not need to enable "allow creation...", but you do need a layout for Table2 in your file.

              • 4. Re: spent hours dont understand help
                moogie

                     you made my day  -   i didnt know about "allow creation"  -  thanks

                • 5. Re: spent hours dont understand help
                  moogie

                       how do you return to the same record after script runs?

                  • 6. Re: spent hours dont understand help
                    philmodjunk

                         Add Go to Layout [original Layout] to the end of the script.

                    • 7. Re: spent hours dont understand help
                      moogie

                           put "go to layout (original layout)"   not the layout name and it brings you back to last record found  - not record you were on when script initiated  -  tried rearranging order  -  changed go to layout when you start from (name of layout) to (original layout)  -  nothing works  -  what am i doing wrong

                      • 8. Re: spent hours dont understand help
                        philmodjunk

                             What is the exact script you ended up with? I incorrectly assumed that you were doing the second option that I suggested, but a review of your posts suggest that you likely used the first script which does not change layouts to create new, related records.

                             If you are looping through a set of records using set field and "allow creation..." to create related records, my best guess is that you started from the first record in your found set.

                             If so, you just need to use Go to Record/Request/Page [First]

                             to return to the first record in your found set.

                        • 9. Re: spent hours dont understand help
                          moogie

                               set error capture (on)

                               go to layout (original layout)

                               show all records

                               enter find mode(restore)

                               perform find

                               replace field contents (no dialog; ???????::????????; "x")  

                               loop

                               set field (...........// used to make new record

                               ........

                               ........

                               go to record/request/.....(next;exit after last)

                               end loop

                               exit script

                               go to layout (original found)

                               show all records

                               enter browse mode     //\\      i want to see original record on screen when i ran script

                          • 10. Re: spent hours dont understand help
                            philmodjunk

                                 As posted in my previous post, use go to Record/Request/Page [First] to return to the first record in your found set.

                                 And there's no need for the Enter browse mode step, your window is already in that mode by the time it reaches the end anyway.

                            • 11. Re: spent hours dont understand help
                              moogie

                                   the script searches for records in file "A"  -  after finding records it marks a field in file "A" with an "x" so it wont find record next time  -  it then makes a new record in file "B" for every record found in "A"  -  dont want to go to first record in found set  -  when script ends i want to see the record that was on the screen when i pushed the button to start script

                              • 12. Re: spent hours dont understand help
                                philmodjunk

                                     Then you'll need to save that record's primary key in a variable and use another scripted find to find it again when you are finished.

                                • 13. Re: spent hours dont understand help
                                  moogie

                                       ive tried     Set Variable ($$Original record; Value;Get (RecordID)) after Set Error   - at end of script Go to Object (Object Name:$$original record)  -  doesnt work  -  either im useing wrong controls or in wrong place  

                                  • 14. Re: spent hours dont understand help
                                    philmodjunk

                                         Yep, wrong functions, wrong script step. Go to Object puts the focus on a named object on your layout such as a field, button, tab panel, portal, etc... It won't change records.

                                         Get (recordID) might work, but only if you have the record ID in a field. The value returned by Get ( RecordID ) , BTW, is not a good choice for using as a primary key anyway. You should define your own field to use as a primary key. The most commonly used set up for this in FileMaker is a number field set up to auto-enter a serial number.

                                         If you named that field: __pkYourTableNameID then you could put this script step at the beginning of your script:

                                         Set Variable [$OriginalID ; value: YourTable::__pkYourTableNameID ]

                                         and then at the end of the script, you'd use:

                                         Enter Find Mode []
                                         Set field [YourTable::__pkYourTableNameID ; $OriginalID ]
                                         Perform Find []