1 Reply Latest reply on Sep 11, 2013 9:40 AM by philmodjunk

    Set Field Problem



      Set Field Problem


           Seems like this should be simple but I'm getting odd results.  I have a script that is supposed to update a set of fields based on a global variable.  It reads something like this:


           IF [$$globalvar = 1]

               SET FIELD [table1::fieldname1; table2::fieldname1]

               SET FIELD [table1::fieldname2; table2::fieldname2]

           ELSE IF [$$globalvar = 2]

               SET FIELD [table1::fieldname3; table2::fieldname1]

               SET FIELD [table1::fieldname4; table2::fieldname2]

           END IF



           Instead of getting the VALUES from the fields in table2 to be stored in the fields on table1, it is storing the NAMES of the fields.

           Very strange.  Anyone have a thought?



           While waiting for a reply to this post, I continued messing with the situation.  The data in my table2 appears in another layout, not in a portal.  Maybe that's the issue.  Instead of directly referencing the field in the SET FIELD command, I seem to have solved the problem by storing the value in a local variable and then referencing that variable. 


        • 1. Re: Set Field Problem

               If you see the names of the fields instead of their values, I can only guess that you have the second parameter expression inside quotations marks such as:

               SET FIELD [table1::fieldname1; "table2::fieldname1"]

               But a script step like this that references fields from two different table occurrences, may fail and not set the field to any value at all.

               SET FIELD [table1::fieldname1; table2::fieldname1]

               will only work if both fields from both tables are accessible at the moment that the step is executed. That will be determined by what record is the current record on the current layout and by the relationships you have defined in your database.


               You might be on a layout for table1. If a related record in table 2 exists for the current record, the script step will work. If not, it will fail. (And no error message will pop up to tell you that it failed. You'll only know this by the fact that the value of the first field did not change.)

               The same is true if this script step is executed on a layout for Table 2.

               Where this frequently trips up "newbies" is when the current record in Table1 is a new record just created by a prior script step. Since it's a new record, all fields--except those with auto-entered values, will be empty and thus the new record frequently does not have ANY links to records in other tables.