Guide to a cross-platform container field with reference to stored document
This keeps coming up as a question, either by itself or as part of the larger question of how to store files "as a reference" in a container field on one computer and have it available to other computers opening the db on a network.
a) The files that will be stored "as a reference" must be on a computer that is not the computer that any of the various FileMaker users actually sits at. That is because the path must be identical from all the computers (e.g., Mounted Server/Folder/Subfolder/File.xls), and if you are sitting at that computer ITSELF that is not the path to that file (e.g., Macintosh HD/Users/AHunter3/Documents/Folder/Subfolder/File.xls, instead!)
b) Moving on to the cross-platform issue: even when the document file sits on a file server as it should, if the reference is inserted by a PC user the path might be like so:
J:/Folder/Subfolder/File.xls
or like so:
//Mounted Server/Folder/Subfolder/File.xls
... and the Macs in the same office will not be able to reconcile that PC style filepath! Likewise if the Mac stores the file as a reference, the Mac style path will not work, either! So what you must do is create a calculation field of result type "container"; the calc field uses a formula that examines the platform of the current user, compares it to the platform used to store the reference (as I will show, you can determine that), and if they are a mismatch, converts the path. Here are the steps to setting that up.
c) Create a temporary button next to the regular container field you store documents in, with the button-function: Show Custom Dialog [ GetAsText (YourTable::ContainerField) / OK].
d) From a Mac, store a document as a reference, using a document that is on a file server that both the Macs and PCs can get to. Then click your button and jot down the exact path as the Mac perceives it. It will start with "filemac://" and the rest of it will be volume name, folder/, subfolder etc, then document name.
e) From a PC, store the exact SAME document as a reference and click the button and again jot down the exact path as the PC perceives it. It will start with "filewin://" and the rest of it will be volume name, which on a PC may be a logical "mapped" drive letter or it may be a network share name, then folder, subfolder, etc, then document name. Now you have both the PC and Mac versions of the path to the exact same document.
f) Create a formula that will evaluate GetAsText (YourTable::ContainerField) and then return that exact string if PatternCount (GetAsText (YourTable::ContainerField), "filemac")>0 and you are on a Mac — i.e., Abs(Get(SystemPlatform))=1 — and will also return that exact string if PatternCount (GetAsText (YourTable::ContainerField), "filewin")>0 and you are on a PC — i.e., Abs(Get(SystemPlatform)) = 2:
Let (
[filepath = GetAsText (ContainerField);
platform = Abs(Get(SystemPlatform))];
Case (PatternCount (filepath, "filemac")>0 and platform = 1, filepath; PatternCount (filepath, "filewin")>0 and platform = 2, filepath)
)
g) You're not done with that formula. So far you've only accomodated cases where it was stored by the same platform you are currently using. Now we make the translation part. Compare the exact PC and Mac file paths I had you jot down in steps d and e, and you'll see that only a bit at the front (the filemac or filewin parts plus how it references the front part of the path string) are different, and everything past that point is the same. So you use Substitute() to swap out the Mac part and the PC part. You end up with a formula something like this, although it will differ a bit for you depending on the exact file paths you get on your Mac and PC in YOUR office:
Let (
[filepath = GetAsText (ContainerField);
platform = Abs(Get(SystemPlatform))];
Case (PatternCount (filepath, "filemac")>0 and platform = 1, filepath; PatternCount (filepath, "filewin")>0 and platform = 2, filepath;
PatternCount (platform = 1; Substitute (filepath; "filemac://Server/", "filewin://J:/"); platform = 2; Substitute (filepath; "filewin://J:/", "filemac://Server/")
)
{aside: you'll note that in the part I just added, for the Mac part, I did not have to explicitly state that patterncount of "filemac" in filepath is NOT greater than 0. That's already been handled: if it were true that "filemac" occurred in the filepath and platform was 1, the first chunk of the Case() statement would have already caught it. So now that I am down here, saying "platform = 1" means "any remaining situations where platform = 1 that I did not already tell you how to handle". Likewise for the PC portion: we already know what we're doing with cases where platform = 2 and there's a patterncount > 0 of "filewin" in the filepath.}
h) Finally, your calculation field, like all calculation fields, has a storage option tab. Go to it and click "unstored, calculate as needed". You want it to make a fresh "right now" assessment of what platform the current user is currently using. If the value of this calc gets stored, it won't do that, it will evaluate once and not evalute again unless the fileref in the container field itself gets replaced!
Now you're done with the calcfield...
i) On your layout, place the calculated container field UNDER the regular one, and put a button labeled "Launch" or some such thing that goes to the calculated container field [select/perform] and that is how you launch the file. To store references IN the field, you do it the regular way, inserting the file as reference into the regular container field.
Your new post is loading...