10 Replies Latest reply on Jul 25, 2013 1:01 PM by Matty_1

    Get (LayoutTableName) ??

    Matty_1

      Title

      Get (LayoutTableName) ??

      Post

           Is there a way to get the actual table name instead of the occurrence for any given layout?

        • 1. Re: Get (LayoutTableName) ??
          philmodjunk

               No there is not. But many developers use a naming convention that includes the data source table name as part of each table occurrence name so you may be able to come up with a way to get the data source table name from the occurrence name.

               Since virutally everything works from the occurrence name, how does getting the data source table name help you?

          • 2. Re: Get (LayoutTableName) ??
            Matty_1

                 It's actually to have a code that would work across all layout and tables without having to make several dozen individual codes calling on the records serial ID that I've created.

                 Say I have a table called Purchases, my serial field is PurchasesID and I can't use the occurrence because my naming convention for occurrences is always NameOfTable_RootTableLinkedTo .... say I used the same amount of letters for the root every time I would have maybe come up with Right() sort of function but I haven't and it's way too late now to change it all.

                 If I could call upon the actual table name that all I would need is to add (&"ID") to the function and I would have the serial field for every table.

                 :(  too bad!

            • 3. Re: Get (LayoutTableName) ??
              philmodjunk

                   If you always have an NameOfTable_

                   Then that underscore is all you need to extract the data source table name.

                   Let ( T = Get ( LayoutTableName ) ;
                            Left ( T ; Position ( T ; "_" ; 1 ; 1 ) - 1 )
                          )

                   The name will not have to be a specific number of characters in length.

              • 4. Re: Get (LayoutTableName) ??
                LaRetta_1

                     Hi Matty,

                     That is one reason I name my primary keys simply ID.  Then I can use:

                     Get ( LayoutTableName ) & "::ID"

                      

                • 5. Re: Get (LayoutTableName) ??
                  philmodjunk

                       That's a very Good point. A consistent field name for the PKs and Fks makes all of this much simpler.

                       Another useful trick for indirect field references is to put GetFieldName ( YourTableOccurrence::YourFIeld ) in the optional script parameter box for a call to a given script. This allows you to use Set Field By Name [ Get ( ScriptParameter ) ; Expression goes here ] or similar indirect references, but should I go to Manage | Database | Fields and rename that field, this still works as GetFieldName will successfully return the modified field name.

                  • 6. Re: Get (LayoutTableName) ??
                    Matty_1

                         Right, in hindsight I would have used a standard naming convention for my serial fields across all databases but I've yet to run into a situation like this until now.  When I first started developing my own scripts a few years ago I was working hard at trying to take a one script for all approach but was told on the form that it was virtually impossible to do and so I abandoned the idea and therefor stopped thinking of the most efficient naming convention for occurrences and fields.

                          

                         Kicking myself now!

                    • 7. Re: Get (LayoutTableName) ??
                      philmodjunk

                           Except for indirect references that use quoted text to refer to the field name (set field by name, getField...), you can easily rename your fields and the changes "flow" throughout your database. So you may find that renaming your fields to get a consistent naming convention may be something that isn't too terribly difficult to do.

                           What you are trying to do can be very tricky and in some cases a lack of the appropriate indirect reference option for certain script steps (such as Go TO Related REcords) may make what you are trying to do impossible. But it depends on the script.

                      • 8. Re: Get (LayoutTableName) ??
                        Matty_1

                             Yes you're right.  I should have probably taken a hybrid approach and used the one for all script when and where I could and created custom scripts when I had no choice.  I was a newbie at the time so going back now would be somewhat of a scary task when I've got hundreds of scripts and a live database to deal with over and above my day to day job that I need to perform.  I did however move over to a separated model roughly 4 months ago so I could also slowly chip away at it on my spare time...

                        • 9. Re: Get (LayoutTableName) ??
                          Matty_1

                               My naming convention has the root table always at the end so I had to switch it to this:

                                

                               GetField (
                                
                               Get ( LayoutTableName ) &
                                
                               "::" &
                                
                               Let ( T = Get ( LayoutTableName ) ;
                                        Right ( T ; Length ( T ) - Position ( T ; "_" ; Length ( T ) ; -1 ))
                                      )
                                
                               & "ID"
                                
                               )
                                
                               and it works!
                          • 10. Re: Get (LayoutTableName) ??
                            Matty_1

                                 I just realized that you were correct Phil the Left is what I needed.  I don't know what I was thinking ... must of been too early in the morning.  Anyways, for the time being both worked because in the example I'm using it in there is only one table name (IE: Purchases) so it does matter if the entry is left or right but any other time it would have to be Left for my naming convention.