3 Replies Latest reply on May 16, 2017 8:15 AM by philmodjunk

    how to get the PK of the underlying TO in a script

    cortiel

      I want to create a generic script to add records

       

      how do I know the name of the table and the name of the PK

      so I can pass it on the the child record

      assumng i dont automatically add child record

       

      P

        • 1. Re: how to get the PK of the underlying TO in a script
          philmodjunk

          Look it up using manage | database?

           

          There is no method other than using a rigorous naming convention to reference the PK as there is no such thing as a "primary key" field option, it's only in how we choose to define and use a field that makes it a PK.

           

          So if you named all PK's after this convention:

           

          __pkTableNameID

           

          Then:

           

          "__pk" & Get ( LayoutTableName ) & "ID"

           

          would return the name of the field.

           

          Let ( TO = Get ( LayoutTableName ) ;

                  GetField ( TO & "::" & "__pk" & Get ( LayoutTableName ) & "ID" )

                ) // Let

           

          Would return the value of the current record's primary key, but only if the current layout's TO is named in accordance with that specific naming convention.

          • 2. Re: how to get the PK of the underlying TO in a script
            cortiel

            layouttablename

             

            exactly what ai was looking for

             

            Thnaks

            • 3. Re: how to get the PK of the underlying TO in a script
              philmodjunk

              Note however, that this is an example of what I call "brittle design". You do gain some code flexibility in that you are using indirect field references, but by including portions of the field and/or table occurrence name in quotes, you have also created a design where renaming a field or table occurrence causes this calculated reference to fail. No warning messages will appear about this calculated reference if you or another developer later renames the TO or field either.

               

              So there are both pros and cons to this approach.