5 Replies Latest reply on Apr 4, 2012 10:54 AM by philmodjunk

    Adding records from Global Fields to another table?

    MikaelLehmann

      Title

      Adding records from Global Fields to another table?

      Post

      Hello!
      I have a layout with a number of fields and a portal. Above the portal, I have some global fields that the user must enter values into. Then the user must click the "Add New Record" button and this should generate a new entry to the portal on the page. I would not wish the user to enter data directly in the portal, the entry should be generated only when the user clicks the button.

      How do I add a record to a table from a set of global fields from another table, I guess is my question?

      Thanks,

        • 1. Re: Adding records from Global Fields to another table?
          philmodjunk

          You have a relationship linking your layout's table to the portal's table. Let's assume it's set up like this and then you can substitute your table and field names for mine to make this work:

          LayoutTableOccurrence::PrimaryKey = PortalTableOccurrence::ForeignKey

          For purposes of example, let's assume two global fields: gName and gAddress

          Then your script would look like this:

          Set variable [$Key ; value: LayoutTableOccurrence::PrimaryKey ]
          Freeze Window
          Go to Layout [PortalTableOccurrence]
          New Record/Request
          Set Field [PortalTableOccurrence::ForeignKey ; $Key ]
          Set Field [PortaltableOccurrence::Name ; LayoutTableOccurrence::gName ]
          Set Field [PortaltableOccurrence::Address ; LayouttableOccurrence::gAddress ]
          Go to Layout [originalLayout]

          Note: global fields can be defined in any table and they will be accessible from any layout and record in your file.

          • 2. Re: Adding records from Global Fields to another table?
            MikaelLehmann

            Hello!
            Thank you for your prompt response! It works great! I have tried this for several days and then you resolve it in minutes. Thank you!

            BUT if the user clicks on one of the portal rows, I want the information to be displayed in the global fields. The user should now be able to edit the information and then click the "Save Changes" button. The changes should be reflected in the portal.

            Thanks,

            • 3. Re: Adding records from Global Fields to another table?
              philmodjunk

              Write this script:

              Set Field [LayoutTableOccurrence::gName ; PortaltableOccurrence::Name ]
              Set Field [LayouttableOccurrence::gAddress ; PortaltableOccurrence::Address ]

              Enter layout mode and select all the fields in the portal row.

              Select button setup and set it to perform the above script.

              If you also set a global variable or global field with the RecordID in the same script, you can use conditional formatting to change the fill color of the fields of the portal row just clicked so that the user can see which clicked portal row put the values into the global fields for editing.

              • 4. Re: Adding records from Global Fields to another table?
                MikaelLehmann

                Thanks, but how do I update the record in PortaltableOccurence?

                • 5. Re: Adding records from Global Fields to another table?
                  philmodjunk

                  Good question. Sure you want to use global fields for this?

                  There are other options for getting to the portal row's data that may not be as complex to set up.

                  Sticking with what you have at the moment, we'll need to do some additional work on your portal table.

                  If you don't already have a serial number field in your portal table that serves as a primary key, define one. I'll call it Primary Key for this example: Define a field with global storage, gSelectedRecordKey.

                  In Manage | Database | relationships, make a new table occurrence of Your PortalTable by clicking it and then clicking the duplicate button (2 green plus signs). You can double click the new occurrence box to get a dialog to appear where you can rename the new occurrence box.

                  We have not duplicated a table. Instead, this is a new reference to the same table already present in your database.

                  Add it to your relationships like this:

                  LayoutTable::gSelectedRecordKey = PortalTable 2::Primary Key

                  Change your script that copies data into the global fields when clicked to be:

                  Set Field [LayoutTableOccurrence::gSelectedRecordKey ; PortalTableOccurrence::Primary Key ]
                  Set Field [LayoutTableOccurrence::gName ; PortaltableOccurrence::Name ]
                  Set Field [LayouttableOccurrence::gAddress ; PortaltableOccurrence::Address ]

                  Now this code can be your "save changes" script:

                  Set Field [PortaltableOccurrence 2::Name ; LayoutTableOccurrence::gName ]
                  Set Field [PortaltableOccurrence 2::Address ; LayouttableOccurrence::gAddress ]