4 Replies Latest reply on Jun 25, 2010 11:51 AM by tony24601

    How to generalize a script for any table.

    tony24601

      Title

      How to generalize a script for any table.

      Post

      Hello,

      I have a quick question, that I haven't been able to find an answer to. I'm trying to make a better navigation system. Right now I have a script that requires Assets::_nav but I'd like to use the script globally. That is, i'd like to be able to add _nav to every table and be able to use the same script in each one. More or less, i'd like to be able to do (this table)::_nav. So, it would work for Assets::nav and Employee::nav, and anything else. Is this possible?

       

      Thanks,

       

      -Tony

        • 1. Re: How to generalize a script for any table.
          philmodjunk

          There are ways to do this, though setting up your script this way has it's own risks...

           

          Setfieldbyname can be used to change the value of such a field.

          GetField can be used to read the value of such a field.

           

          The risk you take on is that both steps fail silently if their table::Field name expression evaluates to a name that doesn't exist. That is, the script using these steps won't display an error message nor will it halt the script if they fail. You won't know they did unless you specifically test for an error (get (lasterror) ) or you happen to notice that the script no longer works as expected.

           

          You can break such a script in this manner simply by renaming one of the referenced fields and or tables in Manage | Database.

          • 2. Re: How to generalize a script for any table.
            tony24601

            I'm not so worried about risking that, its just for navigation, so if something breaks it'll be really obvious. I porbably should have been slightly more specific though (didn't realize there was a difference until i tried to implement what you said). I see how to do what you're saying with the Set Field By Name ( I just made the target field Get ( ActiveFieldTableName ) & "::_nav"), but I also need to do it in an Else if(Assets::_nav = "Employee List"). I can't pull the same trick there can I?

            • 3. Re: How to generalize a script for any table.
              philmodjunk

              That's how you'd use GetField

               

              Else if(GetFIeld ("Assets::_nav" ) = "Employee List")

               

              And you can put a text expression in place of the quoted text to refer to a different table::field.

              • 4. Re: How to generalize a script for any table.
                tony24601

                Thanks a lot, that got it working.