11 Replies Latest reply on Jan 3, 2013 6:53 AM by pedantic

    Inherited Project--trying to understand...

    pedantic

      Hello everyone.

       

      I inherited a project about a month ago and I am trying to get through its code to understand how it works.

       

      Overview: The project imports data from two local text files into local tables, processes the data to make it more compatible with other systems we use, then the data is uploaded to a database on our Filemaker server.

       

      The database and scripts were put together in FM 8.5 but work just fine in FM 11. I have not tried to port them over to FM12 yet but that may happen soon.

       

      The problem is that I have carefully stepped through the scripts to find the exact line where the data is moved up to the server, but the context doesn't make any sense. Here are the lines of code that I have identified as relevant to the process:

       

      # This just creates a window; it does nothing to affect context as far as I can tell.

      New Window [Name: "Import"; Height: 50; Width : 50]

      #

      # List_View is a local layout containing the data to be moved to the server and its context is OD_Panel_Process. OD_Panel_Process is a table in the local database--not on the server.

      #

      Go to Layout ["List_View" (OD_Panel_Process)]

      #

      # These next two commands are more administrative than actually productive, but I include them because you would want to know.

      #

      Show All Records

      Replace Field Contents[yada yada]

      #

      #

      # Here's the command. It moves the data from the OD_Panel_Process table in OnLInePanelFeed_Rename.fp7

      # to the OD_Data table in the CD_Panel database on the server. But nowhere do I see a command to force the data

      # to the CD_Panel database.

      Import Records [No dialog; "OnLInePanelFeed_Rename.fp7"; Add; Mac Roman]

       

       

      As far as I can tell, the "to" table should be the context table of the List_View layout, which is OD_Panel_Process, a local table. Yet I have verified that the data is placed in the server table when the Import Records command is executed.

       

      Now, looking at the Relationships graph, I note that there is a relationship between OD_Panel_Process and the table occurrence OD_Data_Record_Check, an alias for OD_Data. There is also another relationship between the same tables through two intermediary table occurrences.

       

      Does Filemaker do some kind of strange magic when an Import command is executed and two tables are related? That's the only thing I can think of, but I cannot find any in-depth documentation that discusses it.

       

      R,

      John

        • 1. Re: Inherited Project--trying to understand...
          LyndsayHowarth

          I suspect that the import is not importing all data as new records but rather importing the data based on a match field... Have a close look at the import dialog and the settings below the LHS field list.

           

          It may also be that the first import is forcing some lookups or auto calculations. Certainly the Replace gives a hint that something like that is happening.

           

          HTH

           

          - Lyndsay

           

          Sent from my iPad

          Lyndsay Howarth

          11th Hour Group Pty Ltd

          • 2. Re: Inherited Project--trying to understand...
            comment

            pedantic wrote:

             

            As far as I can tell, the "to" table should be the context table

             

            Not necessarily. Within the Import Records[] script step options, you can select any TO to be the target table of the import, with no regard to the current context. As long as the TO exists on the local relationship graph, you can import into it. It doesn't need to be related to the current TO and it doesn't even need to have a layout.

            • 3. Re: Inherited Project--trying to understand...
              gdurniak

              FileMaker CAN "magically" create related records, if non exists, when a field is set ...

               

              show the tables in question in separate windows, then try the steps you describe by hand,  with just one or two records,  and see what happens

               

              the logic may become apparent, once you can see it happen

               

              greg

               

               

              > Does Filemaker do some kind of strange magic when an Import command is executed and two tables are related?  That's the only thing I can think of ...

              • 4. Re: Inherited Project--trying to understand...
                pedantic

                Here's some additional information.  I ran a report in FM11 to see what might pop up.  I then looked at the script I quoted above, the Upload_To_CDPanel script.  I took a careful look at the Import command and the documentation in the report very specifically states that the target table is the OD_Data table, which is on the server and based upon the behavior of the code, is no surprise. 

                 

                If the target is not explicitly identified in the code (as you can see if you look at my original post) then how can I find out which target the import is directed at?  More importantly, how do I specify the target table in future scripts?

                • 5. Re: Inherited Project--trying to understand...
                  gdurniak

                  if no other imports are done, it is possible that it simply reverts to the "last" import

                   

                  try an import to OD_Data, and see what happens

                   

                  also try printing all your scripts to PDF. That often shows additional detail

                   

                  greg

                   

                   

                  > If the target is not explicitly identified in the code (as you can see if you look at my original post) then how can I find out which target the import is directed at?

                  • 6. Re: Inherited Project--trying to understand...
                    comment

                    pedantic wrote:

                     

                    If the target is not explicitly identified in the code (as you can see if you look at my original post)

                     

                    No, I cannot see that in your original post. On the contrary, the inclusion of "Add; Mac Roman" shows that import order - and therefore the target table, too - has been specified.

                    • 7. Re: Inherited Project--trying to understand...
                      pedantic

                      Thank you, Mr. Horak for your contribution.  Though I don't see how specifying that the import routine should "add" records (as opposed to  "update") and should expect the "Mac Roman" character set implies order and target table, I will just have to assume you know what you are talking about.  I freely admit I am clueless.

                       

                      What I was saying in my previous post is that looking at the script fragment that I included in my first post (or for that matter, the whole script, most of which I left out), I see no place where it overtly says "Use OD_Data as the target table," or syntax to that effect.   So somewhere along the line the target table must be implied.  Where is that implication made?  I know it's happening because I have stepped through the script and watched data flow from the source file into the OD_Data table.  I just don't know how the original scripter made it happen.  And if I don't figure it out I could easily break the whole system because of my ignorance, which would not be good for my paycheck (grin).

                       

                      So in conclusion either the "to" table is overtly identified and I am completely missing it, or somewhere along the line the "to" table is implied and I am missing that.  Can you help with either?

                      • 8. Re: Inherited Project--trying to understand...
                        comment

                        If you select the Import Records step and look in the bottom right corner of the Edit Script window, you will see that the 'Specify import order' checkbox is checked. How do I know this, without seeing your file? I know this, because the script step - as shown in the Edit Script window - includes the "Add; Mac Roman" settings. If you uncheck the checkbox, then no such settings will be included. It doesn't matter if the setting is "Add" or "Update", "Mac Roman" or "UTF-8".

                         

                        Note that I have stressed "as shown in the Edit Script window". Now, if you print your script, you will see that it looks something like:

                         

                        Import Records [ Source: “YourLocalFile.fp7”; Target: “YourExternalTO”; Method: Add; Character Set: “Mac Roman” ]

                         

                        Note that even this does not fully reflect all of the settings stored with the script step. For example, the field-to-field mapping is not shown.

                        • 9. Re: Inherited Project--trying to understand...
                          pedantic

                          Thank you, Mr. Horak.  I appreciate you sticking with me.  I now understand why you made your assumption. Additionally, if you click the "Specify" button to the right of the"Specify import order" checkbox, at the top of the Import Field Mapping dialog box that appears we have two dropdown controls; one specifies source, the other specifies target.  The target dropdown reflects the name of the table that is getting updated by this script.  That is the "how" that I needed to know.  Interestingly enough, the specification is overt and not implied.  One just needs to know where to look to get the information.

                           

                          I also learned a bit more about Filemaker script, ah, style.  I am a programmer, not a scripter by trade.  In programming, its rare that the code hides such detail from the programmer.

                           

                          Thanks to everyone who contributed to this discussion.

                          • 10. Re: Inherited Project--trying to understand...
                            gdurniak

                            as suggested above, if you PRINT your scripts, all the detail is there

                             

                            FileMaker's "Help" is also very detailed

                             

                            and yes, stuff is "hidden" all over the place ...

                             

                            greg

                             

                             

                            > In programming, its rare that the code hides such detail from the programmer.

                            • 11. Re: Inherited Project--trying to understand...
                              pedantic

                              Mr. Durniak, it wasn't the fact that I didn't know that OD_Data was the target.  As I mentioned in my second post to this discussion, when I ran a report on the database in FM11 Advanced, it identified the target table. Additionally I stepped through the code with a specific set of unique and easily identifiable data and I watched as the data were transferred from one table to the other when the Import Records script step was executed. It was the fact that I didn't know how OD_Data was getting specified.  Not knowing how left me in danger of breaking things when I started modifying things.

                               

                              As to the Filemaker Help article on the Import Records step, the only thing it says about the target is this:

                               

                                   Note when import source fields and target fields are mapped using matching names, field name matching is performed dynamically each time the script step is performed.

                               

                              That's from the Filemaker Pro Help article that comes with Filemaker Pro 11 Advanced.  Is there another place I should be looking?

                               

                              Take care,

                              John