I need to create a script to Get a value from one Field in a Table and Insert that same value in another Field in a different Table? The script will be attached to a button.
Thanks for any help,
One way is to store the value in a script variable and use that stored value when assigning to the field in the other table.
Go To Layout["FirstTableLayout"]
Set Variable [$theValue; Value:FirstTable::myField]
Go To Layout["SecondTableLayout"]
Set Field [SecondTable:myOtherField; $theValue]
Specifying a field also specifies the table to which it belongs. For example: "MyTable::MyField" The double-colon separates tha table name from the field name.
You should thus be able to directly insert the value from one field in one table to another field in a different table like so:
My approach is to have the script
Go to Table A layout
Select Field X, select all, copy
Go to Table B layout
select Field Y, select all, past
You just copied a value from Table A to Table B.
In my opinion, the necessity to switch layouts to perform your desired action is one of THE major nuisances in FileMaker.
In FM12 the situation has been alleviated somewhat by the new ExecuteSQL command.
Using this command and SQL syntax you can query the values of a field belonging to a certain record.
However, it is still not possible to write this value to another field.
As far as I know an SQL plugin is still the only solution to perform the sequence of querying a value from just any record in any table and then writing it to some other record in another table.
We've been using an SQL plugin excessively for this purpose for quite some time now and, while it doesn't solve each and every problem, we are happy that it solves us an estimated 95% of all problems related to your question.
See chapter 7 in the "FileMaker 12 ODBC/JDBC Guide" (http://www.filemaker.com/support/product/docs/12/fmp/fm12_odbc_jdbc_guide_en.pdf) to find out more on the SQL syntax supported in FileMaker.
I'm sorry but I have to disagree with you.
What you are describing works for global fields only.
It doesn't work for regular fields, though.
Assuming that you are on a layout showing records of FirstTable, there is no way of knowing which recrord you are referencing in SecondTable. How should FileMaker decide on which record to set SecondField? It simply can't. That's the problem and that's why TomHays and email@example.com provide scripting solutions where you have to jump from layout to layout to actually select the appropriate records to update fields on.
Oops. My bad.
Using Copy-Paste is not a recommended technique anymore since FM8 or later, because you are overwriting the precious clipboard contents of the user. Use a variable instead, as Tom Hays suggested.
Retrieving data ...