4 Replies Latest reply on Jun 15, 2015 5:05 AM by GuyStevens

    find a record using a global variable



      find a record using a global variable


      hello, I would like, via script, open a layout and display a specific record. i have the objectID of this record in a globale variable: $$ObjectNoSelected. i used GoTorelated record function, my layout is opened but how can i tell him to open the desire record (objectID=$$ObjectNoSelected) ? thanks

        • 1. Re: find a record using a global variable

          I don't know what the ObjectID is.  Is that the same as ObjectName?  If so it belongs to the layout, not to the record.

          Why not just trap the Record's Unique ID as the variable, and then perform a scripted find for that?

          • 2. Re: find a record using a global variable

            Assuming objectID is a serial number field or other field that stores a value that uniquely identifies the record the Find script might look like this:

            Go To Layout[//select the layout where you want to display this record]
            Enter Find Mode []
            Set Field [YourTable::ObjectID ; $$ObjectNoSelected ]
            Set Error Capture [on]
            Perform Find []

            If you really want to use Go To Related Record, you'd need a relationship that matches a field in the current table to the ObjectID field, then use a script like this:

            Set Field [YourCurrentLayoutTable::KeyField ; $$ObjectNoSelected]
            Go To Related Record [....

            • 3. Re: find a record using a global variable

              I have a very similar problem that PhilModJunk's post doesn't solve.

              Simple problem description:
              I want to open a layout and have it go to a specific record based on a value stored in a global variable.

              Details of problem:

              LayoutAlpha has a button with this script:
              Set Variable [$$currentContactID; Value:LayoutAlpha::ContactID)
              Go to Layout ["LayoutBeta" (TableOccurenceForLayoutBeta)]

              LayoutBeta has a OnLayoutLoad script:
              #debug start
              Show Custom Dialog ["value of global variable";$$currentContactID]
              #debug end
              Enter Find Mode []
              Set Field [TableOccurenceForLayoutBeta::ContactID ; $$currentContactID]
              Perform Find []

              The value of $$currentContactID is correct in the Custom Dialog.
              But the displayed record in LayoutBeta is some random record that never changes,

              The value that gets stored in $$currentContactID is a primary key in TableOccurrenceForLayoutAlpha but is a foreign key in TableOccurrenceForLayoutBeta (may occur none or many times).
              Am new to FM
              Using FM Pro 10 on Win7

              Also, is there a way to copy Script to clipboard instead of screencapping or laboriously retyping it on this forum (I fear not...)?

              • 4. Re: find a record using a global variable

                Hi Japafm, 

                So you want to show the current contact's record on another layout based on another table?

                Is it possible to create a relationship between the contact ID in the current table and the contact ID in the second table and then simply use a Go To Related Record script step? This should bring you to the contact's record but on the other layout.

                Greetings Guy

                EDIT: If for some reason you can't make a relationship between these tables you might have to create a new Table Occurrence of that second table to make this happen. And then refer to this second table occurrence in your GTRR script step.