Is it possible to use a script for multiple files, and if so, how can this be done? The files may have tables with different names and different fields.
Generally scripts run in the file where they reside. You can call scripts in other file with the Perform Script step.
It is possible, to some degree, to create portable scripts in FileMaker. These are utility scripts that you can import or copy/paste from one file to another with little or no need to repair the transported script before it can work.
This is done by referring to fields via indirection. Instead of set field, you use Set field by Name. Instead of referencing a field's value in a calculation by simply entering the tableOccurrenceName::FieldName into the expression, you use GetField. You then use the getfieldname function to pass the needed tableoccurrencename::FieldName text for each such field as a script parameter.
For some script steps, you can also use indirection via referring to whatever field currently has the focus. This can be done with script steps that start with "insert" and you also have the Get ( CurrentFieldContents ) script.
Sometimes you can also manage indirection using get ( LayoutTableName ) , Get ( ActiveFieldName ) and Get ( ActiveFieldTableName )
Suppose you want to copy one script into one file using copy and paste...
If this is feasable I would first change the name of the target table and target fields to the same and then the script would work without problem, all things being equal.
Then change the names back.
The other method is to copy the script and paste it into the other file and then open it and look for busted names for tables and fields and update them.
To comment on philmodjunk's idea:
At the start of the script you could use
Set variable $field to file:field or something similar
Then when you use set field use set field by name $field
When you copy and paste the script, you only need to change the value of the $field variable to match your file.
Reality is probably a bit more complex...
Retrieving data ...