Reputation: 2873
I'm writing a data-sync/merge solution in FileMaker where I have two data sources and compare/merge them.
That means I have a number of tables and each with a number of fields.
I have for a testing field built my logic and a layout so that FM shows me when the local and remote data source are different and shows me two buttons to let me choose which data to merge into the other set.
I could, of course, manually replicate all the formulas and buttons for all fields in all tables, but that would be insane. Is there a way to tell FileMaker "use this layout and script steps on the buttons for all fields, changing the names of the fields as you go" ?
Or, in other words, I have two fields and two buttons. Let's call them DataA::field and DataB::field. I have a layout that shows them side-by-side. That layout has two buttons with attached logic to show the buttons only if the field values are different. Button A has a "single step" formula that says "set field value of B to A" and button B has a formula "set field value of A to B".
Is there a way to replicate those buttons and their logic to all the fields in my table without doing a lot of manual work ?
Upvotes: 1
Views: 448
Reputation: 516
The answer is YES!
You need...
[Makes your FileMaker work]
fmWorkMate is a free Power Toolbox for FileMaker Developers from www.mrwatson.de (that I have written over the last 10 years or so).
I use fmWorkMate myself to do exactly what you are doing! In my case I'm syncing fields between tables of my FileMaker solution and embedded ESS tables, but the process is the same... make one field / bit of code... and then automatically generate ('multiply') the rest.:-)
So, how?
First up download and install fmWorkMate - This is actually the trickiest part of the process, since the latest version is yet to be published (and I will correct this once published)
Here are several examples to illustrate how you can use fmWorkMate to do what you wish:
The above here does not answer the question directly, rather shows how to replace fields A and B with fields C and D.
The examples are nonetheless useful and illustrative as they stand, and the techniques build on each other.
I have added example 4 as the full answer to the question below.
Copy your buttons out of FileMaker (CMD+C
/ ctrl+c
)
Convert the FileMaker objects to editable XML with fmCheckMate
CMD+2
/ ctrl+2
)[Convert Clipboard FM ⭤ XML]
CMD+2
/ ctrl+2
CMD+OPT+C
/ ctrl+alt+c
)CMD+3
/ ctrl+3
) to change to the XML-Edit viewfmCheckMate > Settings... > XML editor > Small editor
)Find and Replace text in the XML as needed
A
with field C
[F]
ind field (or press CMD+F
/ ctrl+F
)A
[R]
eplace field (or press TAB
or CMD+SHIFT+F
/ ctrl+shift+F
)C
CMD+OPT+A
/ ctrl+alt+A
[R]
buttonALT
and press the [R]
buttonB
with field D
B
and D
Convert back to FileMaker objects
CMD+OPT+V
/ ctrl+alt+V
)Paste into FileMaker (CMD+V
/ ctrl+V
)
Voilá!
(Or rather - oops - did we break it?)
For the particular example you have given - using only one-letter field names A
and B
- the above will break the XML and not work - because the search and replace is across the entire XML, and the letters A
and B
appear in various places throughout the XML and replacing them will make the XML unreadable.
However, 99.9% of the field names you will actually be replacing will be quite unique and it is turns out to rarely be a problem.
For example, if your fields were named Previous value
and Current value
and you wanted to change them to Previous event
and Current event
that would be no problem at all.
Note, however, that just replacing value
with event
would (probably) break the XML as well, since value
is (highly likely) the name of an XML attribute too. In general: Avoid using single word search words like name
, id
, Layout
,.
[And, of course, the table names DataA
and DataB
would work fine as they are unique/non-conflicting with XML tag and element names.]
Let's say you have a list of 10 fields you want to sync:
CustomerName
Company
Street
HouseNumber
City
ZIP
Country
Item
Quantity
UnitPrice
How can we produce code for these 10 fields in a fraction of the time?
Write the code for your first field
Multiply your code
How?
First prepare fmTextMultiplier:
Start fmTextMultiplier
[New]
(CMD+2
/ ctrl+2
) to get an empty recordPaste your field list into the empty Replace field
Press the button [Don't duplicate original]
=> fmTextMultiplier is ready to go:-)
Then
Create some code for field 1 - e.g. the field named CustomerName
Multiply the code
CMD+C
/ ctrl+c
)Edit > Paste FileMaker Clipboard -> XML
(or press CMD+ALT+V
/ ctrl+alt+V
)[Multiply Text x Values]
(or press CMD+5
/ ctrl+5
)[-> FM]
(or press CMD+6
/ ctrl+6
)Check + tweak your code as necessary
The best thing is, this same method works for field definitions, layout-fields, buttons, script steps, scripts, whatever!
Once you have set up fmTextMultiplier once you can use the same multiplier function to multiply all the different bits of code around the fields.:D
Say you are building a calendar and need a series of fields to hold the days:
Day 1
Day 2
Day 3
Day 4
Day 5
Day 6
Day 7
Day 8
Day 9
Day 10
Day 11
Day 12
Day 13
Day 14
Day 15
Day 16
Day 17
Day 18
Day 19
Day 20
Day 21
Day 22
Day 23
Day 24
Day 25
Day 26
Day 27
Day 28
Day 29
Day 30
Day 31
Day 32
Day 33
Day 34
Day 35
Day 36
Day 37
Day 38
Day 39
Day 40
Day 41
Day 42
Gee, this is going to be hard work!
Nope!
We shall use fmTextSeries to generate the series automatically and fmTextMultiplier to multiply the Day 1 code.
Generate the list (series) of field names you need using fmTextSeries
New
if necessaryOK
Text
: Day 1
Times
: 42
Ìncrement
: 1
Prepare fmTextMultiplier
CMD+1
/ ctrl+1
New
to start a new multiplication[Don't duplicate original]
Multiply your code as in Example 2 above
And repeat for any other such fields - or indeed for any code you need (e.g. Day 1 Event Summary field, Calendar Reset script, Calendar picker layout, ...)
Set Field[ DataA::field ; DataB::field ]
So,...
DataA
to a field in DataB
)...Easy! Use a fmCheckMate XSLT transform to swap the source and target fields around!
How?
Additionally to fmWorkMate and fmCheckMate (see above) you'll need the fmCheckMate XSLT library:
Once you have copied the fmCheckMate XSLT folder to your documents folder:
Copy the buttons (or script steps)
Convert to XML using fmCheckMate (see above)
Press the [T]
ransform button
Find and perform the desired transformation
Swap Set Field Target And Value
functionChange
to show only Change functionsScript step
to show only the Change Script step functions[Change]
[Change > Script steps]
[Change > Script steps > Swap]
[Change > Script steps > Swap > Set]
-...[Change > Script steps > Swap > Set > … > … > Value]
[View]
buttonConvert the XML back to FM
Paste into FileMaker
Lol! The direction has been magically changed!
You haven't asked for this directly, but this example may save you having to ask another question.
If your FileMaker-fields and SQL-fields have slightly different names, fmTextMultiplier can deal with that too.
Say you have these FileMaker fields (in your DataA table)
CustomerName
Company
Street
HouseNumber
City
ZIP
Country
Item
Quantity
UnitPrice
And these SQL fields:
customer_name
company
street
house_number
city
zip
country
item
quantity
unit_price
And on your layout you have the two fields with labels next to each other:
CustomerName [CustomerName] customer_name [customer_name]
You can multiply these using fmTextMultiplier by using two columns:
First, you need the two columns separated by tabs (or whatever)
CustomerName customer_name
Company company
Street street
HouseNumber house_number
City city
ZIP zip
Country country
Item item
Quantity quantity
UnitPrice unit_price
Set up fmTextMultiplier like this:
Start fmTextMultiplier
[New]
to start a fresh new MultiplicationPaste the above text into the Replace field
Set the Split Values @ char/text
field to {{TAB}}
(or your chosen delimiter)
Choose [Don't duplicate original]
Then you can multiply your code in four easy steps
Copy your code in FileMaker
Multiply it in fmTextMultiplier - as described above
Edit > Paste FileMaker-Clipboard -> XML
[Multiply Text x Values]
[-> FM]
Paste the code back into FileMaker
Organise the multiplied objects in your layout
OK, so step 4 is not that easy because all of the multiplied layout objects end up in a big pile on top of one another, which is a real pain to pull apart - if you started with 4 separate layout objects, that is.
On the other hand, if you...
You can then just
Arrange > Distribute > Vertically
Et voilá... all the rows are in exactly the correct position!
There is an also a tool for performing multiple conversions to a text, fmTextConverter.
So If you have some code that operates on your FileMaker-fields, and you want the same code to do the same to your SQL-fields, you can simply
Set up fmTextConverter
[New]
to create a new text ConversionThen
Copy your code out of FileMaker
Convert with fmTextConverter
Edit > Paste FileMaker Clipboard -> XML
[Convert text now]
[-> FM]
Paste it back into FileMaker
Note: If one of your field names is a substring of another field name then the substitution will go wrong, if the substring is converted first.
fmTextConverter highlights this problem and offers a sort button, which sorts longer strings to the top, ensuring that the substring is never converted first!
Note too that fmWorkMate is highly optimised for efficient batch work - there are lots of keyboard shortcuts and settings to make repetitive work efficient.
Upvotes: 1