5 Replies Latest reply on Oct 10, 2014 2:08 PM by philmodjunk

    How to calculate a table name in a script?

    SteveFransen_1

      Title

      How to calculate a table name in a script?

      Post

      I'm using a script to set the content of a field to the value of a local variable.

      I'd like to calculate the table name and field name in the script so I can pass those in as parameters and reuse the script, rather than duplicating the script with hard coded table and field names for each table and field combination.

      Set Field By Name will let me calculate the field name.

      Is there a way to calculate the table name?

      Thanks

       

        • 1. Re: How to calculate a table name in a script?
          philmodjunk

          calculating the actual table name will do you no good.

          Set field by name calculates the Tutorial: What are Table Occurrences? name and field name.

          Set field by Name ["YourTableOccurrence::YourField" ; calculated expression goes here ]

          will assign the value of the calculated expression to a field named YourFIeld, using the table occurrence called "YourTableOccurrence".

          Note that the calculated syntax is exactly the same as the syntax that you see in the first parameter of set field, but with out the quotes:

          Set Field [ YourTableOCcurrence::YourField ; Calculated expression goes here ]

          A table occurrence, BTW, is one of the "boxes" found in Manage | database | Relationships and is the required method to access any data anywhere in your database.

          • 2. Re: How to calculate a table name in a script?
            SteveFransen_1

            Got it. That's working now. Thanks!

            At this step of the script I close a popover and am back on the original layout. I need to go to a field in a portal on that original layout, go to the last row of the portal, then set that field to a value. Once again I'd like to reference the field in that Go to Field function by calculation rather than hardcoding the name.

            I can't find a parameter to set the field name by calculation for the Go to Field function. How do I do this?

            Thanks-again

             

             

             

             

             

             

            • 3. Re: How to calculate a table name in a script?
              philmodjunk

              You can't calculate a field name in Go to Field.

              But you can use the inspector to give the field an object name and an object name can be calculated in Go to Object. You can also pass that object name in a script parameter.

              But going to the last portal row and setting a field to a value sounds like you are creating an new related record. There are often better methods to use for that which do not interact directly with the portal.

              • 4. Re: How to calculate a table name in a script?
                SteveFransen_1

                But you can use the inspector to give the field an object name and an object name can be calculated in Go to Object. You can also pass that object name in a script parameter.

                 

                 

                Okay, got that working, thanks.

                But going to the last portal row and setting a field to a value sounds like you are creating an new related record.

                Pretty much. If a related record, meeting certain criteria, exists, I change the value of one of the fields in that record. If not, I create a new related record and set the value of that field.

                There are often better methods to use for that which do not interact directly with the portal.

                Please explain. I'm here to learn and want to learn the best methods.

                Thanks

                 

                 

                 

                 

                 

                • 5. Re: How to calculate a table name in a script?
                  philmodjunk

                  The problem with using a script to interact with a portal is that subsequent layout changes might break your script. Go to portal row, for example, does not specify which portal it is interacting with. You have to use go to object, specifying the object name of the portal before go to portal row to go to the specified portal row.

                  One alternative is to have the script change layouts to a layout based on the portals table, using go to related records or a scripted find to pull up the portal records and then your script manipulates the portal records on that layout before returning. The main draw back to that approach is that the change in layouts can trip a number of different script triggers and can change what object on the layout currently has the focus.

                  A less commonly used additional method is to use a supplementary relationship that matches to a different occurrence of the portal's table and that relationship, under some circumstances can be used to create records in the portal table without leaving the current layout or changing what layout object currently has the focus.