5 Replies Latest reply on Feb 17, 2013 8:20 PM by symbister

    Set Field by Name ?

    symbister

      Title

      Set Field by Name ?

      Post

           (using FMPA 11)

           I have a layout that gives users a button to find the records relevant to them, (script sets a local variable $user), then asks them to step through and add a piece of data to each one, then they click a 'done' button that returns them (if they've filled out all their records) to the first layout, with their button greyed out or otherwise indicating that that user has finished.

           So I thought that I needed a global 'gusername_done' field for each user, which is then set with a value when all records for that user are complete, which I can then use as a conditional test to grey out their button when they return to the home layout.

           I thought that 'Set Field by Name' might be the answer with a calculation like:

           Set Field By Name ["g" & $user & "_done" ; "true"] which compiles but doesn't set the field with a value.

           Am I on the right track and/or is there a simpler way to accomplish this?

        • 1. Re: Set Field by Name ?
          symbister

               Ok so I figured it out - obviously needs to include the freaking table as well:

               Set Field By Name ["transactions::g" & $user & "_done"

          • 2. Re: Set Field by Name ?
            philmodjunk

                 Warning: If you should ever go to Manage | Database | Relationships, find the "Transactions" table occurrence and alter its name, your script step will fail. Renaming this field in transactions could also make the step fail.

                 This may be an unavoidable issue, but sometimes a way can be found to set up the first parameter so that literal text is not used to produce the TableOccurence::FieldName text.

                 Also, the names here suggest that you are using separate fields where you might be better off setting up a table with different records for each user. For one thing, adding an extra user then becomes a process of adding a new record instead of adding a new field.

            • 3. Re: Set Field by Name ?
              symbister

                   Thanks Phil, but my last post was somewhat premature, this isn't doing what I expected:

                   Set Field By Name ["Transactions::g" & $user & "_done" ; "true"]

                   It's not doing anything, even in script debugger the data viewer doesn't show that field...

                   But yes I see your point about user records, thanks

              • 4. Re: Set Field by Name ?
                philmodjunk

                     If no field is being modified, the most common explanation is that some part of the text expression in the first parameter isn't exactly correct and thus does not evaluate to produce the exact table occurrence::Field Name reference needed to access that field and set it to the value of the second parameter.

                     A second possibility is that the Transactions table occurrence might not be accessible from the current Table Occurrence context at the time the script executes.

                • 5. Re: Set Field by Name ?
                  symbister

                       Ok, finally really sorted it - I was trying to use a local variable to construct a fieldname for a global field