Tyra Posted December 10, 2007 Posted December 10, 2007 This is probably a very nebie question, but is there a way to create new directories when exporting records, so that one can group records based on dynamic record ID's? Searched and can't find any info on creating new directories, which probably means Plug-ins...?
_henry_ Posted December 10, 2007 Posted December 10, 2007 Can you give more information on creating directories? Do you mean creating a new folder in the OS system? Or what kind of directories do you mean?
Tyra Posted December 10, 2007 Author Posted December 10, 2007 Correct, a way to create new folders in the file path.
Tyra Posted December 11, 2007 Author Posted December 11, 2007 So, is there a way to create new directories/folders in either Mac OS or Windows from within a Filemaker script? This question must be so silly, that no one wants to answer...lol
comment Posted December 11, 2007 Posted December 11, 2007 Not really - unless you count Perform AppleScript[] or Send Event[] as "from within a Filemaker script".
Tyra Posted December 11, 2007 Author Posted December 11, 2007 Comment thank you, I have decided to just pre-create the folders. But have ran into a new problem. Since I am using a numerical field to tell the script which folder to export to, I have come across the ocassional record that has odd data in it which then causes a error in the export script since it cant find the right folder. So, it there a way to pre-validate the path, or capture/suppress the error like you do in a find. The script needs to run unattended.
_henry_ Posted December 11, 2007 Posted December 11, 2007 Hello Tyra, Since I am using a numerical field to tell the script which folder to export to, I have come across the ocassional record that has odd data in it which then causes a error in the export script since it cant find the right folder. Can you give more specific information on what the "odd data" are? Also, can you attach the Export Script? Maybe with more information, we can help you better...
Tyra Posted December 11, 2007 Author Posted December 11, 2007 The field in question should be numerical 3-6 digits, but users have left blank (I think I have that one covered below), or they put some like "N/A", "?", etc. I was thinking that since FM does a search in order for a valid dirrectory, that I could add a catch all folder called "errors". but not surre if it will still work it the file name contains "." or "/". Not Sure how to just attach a copy of the script. But here is a print out of it. XMLExport Go to Layout [ "XML Export" (IncidentMetaData) ] Set Variable [ $lasttime; Value:IncidentMetaData::xml_lastime ] Set Variable [ $thistime; Value:Get ( CurrentTimeStamp ) ] Show All Records Set Error Capture [ On ] Enter Find Mode [ ] Set Field [ IncidentMetaData::ts_Mod; ">1/2007" ] Perform Find [ ] // Show Custom Dialog [ Title: "Find"; Message: "Finished the find without error"; Buttons: "OK", "Cancel" ] Go to Record/Request/Page [ First ] Loop If [ not IsEmpty ( SiteData::n_RepositoryUID ) ] If [ IncidentMetaData::ts_Mod > $lasttime ] Set Variable [ $Record ; Value:IncidentMetaData::n_SNIMD ] Set Variable [ $UID ; Value:SiteData::n_RepositoryUID&".xml" ] Set Variable [ $path ; Value:Left( $UID ;2 )&"/"&Right (Left( $UID ;4 );2 ) ] New Window [ Name: "xmlexport"; Left: 200 ] Show All Records Enter Find Mode [ ] Set Field [ IncidentMetaData::n_SNIMD ; $Record ] Perform Find [ ] // Show Custom Dialog [ Title: "test"; Message: $Record&"-"&$path&"-"&$UID; Buttons: "OK", "Cancel" ] Export Records [ File Name: "filemac:/Macintosh HD/Databases/XML_Incident_Transfer/$path/$UID" OR "filemac:/Macintosh HD/Databases/XML_Incident_Transfer/errors" ; Grammar: "FMPDSORESULT" ; Character Set: "Unicode (UTF-8)" ; Field Order: [ No dialog ; Format output using current layout ] Close Window [ Current Window ] End If End If Go to Record/Request/Page [ Next; Exit after last ] End Loop Set Field [ IncidentMetaData::xml_lastime; $thistime ]
Fenton Posted December 12, 2007 Posted December 12, 2007 (edited) If you can run this on a Mac, you can use AppleScript to check for the folder. Otherwise there is a free Moo plug-in, Windows-only (I haven't tried it yet; I have Troi File, but it's expensive for this). It can also be done for free with Windows command line, but I don't have it at my fingertips :-] You will need an old-style Mac path to your folder; so you'll have to calculate or write that. You could also get it from a FileMaker field, but it's just written in directly here. You run the AppleScript using a Perform AppleScript step. This is what the AppleScript looks like:* tell application "Finder" if not exists folder "Macintosh HD:Library:WebServer:Documents:" set theError to 1 else set theError to 0 end if end tell // FileMaker will run the code below, setting a global field if needed if theError is 1 set cell "_gError" to 1 end if I'm sure you've got that folder. So it will not set the _gError field in FileMaker. Notice I had to tell the Finder to do the "exists" test, then end tell. Then tell FileMaker to set a global field. Any AppleScript code not within another app's "tell block" will be run by FileMaker (you don't have to tell "FileMaker", unless you stick FileMaker commands within another app's tell block; FileMaker's running the AppleScript, it knows who it is -) So, if you wanted to get the filepath "from" FileMaker, you'd have another (implied) tell block at the top. It could be from either a regular or a global field, depending on whether the value changes between records (sounds like yours might, different folders). In either case the field either must be on the current layout, or you must specify it via its table occurrence or layout name. I think it's usually safer to just use a dedicated layout, and go there first. Otherwise the AppleScript could break if you change the TO or layout name later. In AppleScript you do not have to explicitly declare a variable, you just name it and set it to a value. To get the path from a global field: set folder_path to cell "_gMacFolderPath" To get the path from a regular field, say in a Looping script: set folder_path to cell "_cMacFolderPath" of current record Or, you could just get part of the path from a FileMaker field, and add the rest, at either the beginning or end. Easier really to just build it in FileMaker. Make it an Unstored field, so as not to waste disk space. *You could also create a calculation which builds the AppleScript (with quotes escaped properly), then run it via the Perform AppleScript (•) calculation choice. I seldom use that myself, but for simple things like this it would be fine. Oh yeah, the answer to your implied question is "No, you cannot block the error you get when you Export," so you must find a way to test for the folder. With files it's easier, because you can Import a file [x] Reference only. Then check to see it worked or not. You can capture the Import error, but not the export one. Oh yeah 2, you can create a directory, even a nested directory, via AppleScript, using do shell script. Let us know if you want to do that. ExistsFile.fp7.zip Edited December 12, 2007 by Guest
Tyra Posted December 12, 2007 Author Posted December 12, 2007 Fenton, Thank you so much for the help. Your reply is very helpful, I am still new at this stuff, and keep finding work-a-rounds for what I am trying to get done, but am sure that there are more professioonal ways of doing them. I am playing with the whole apple script thing right now. The FM server is on a Mac which I remote into from Vista, and so not only learning FM, but the Mac OS at the same time. Also throw in some perl which I created a script to auomate the creation of the two tier folder system that I am exporting too. Before your post I had decided to write another script to add a token file in each directory so that I can do the file path check. I had looked at the Trio File plug-in but could not justify the cost for just this issue. You have given me new ideas.. I keep getting more dangerous by the momment.. thank you.
Tyra Posted December 12, 2007 Author Posted December 12, 2007 I got another idea, how would I check to see if the first 4 characters of a field is between "0000-9999"?
comment Posted December 13, 2007 Posted December 13, 2007 It's not quite clear to me what you mean by "between "0000-9999"". Does it mean "0123" would pass, but "a123" or "123" would fail?
Tyra Posted December 13, 2007 Author Posted December 13, 2007 Correct. "0123","012345" would both pass since the first 4 fall with in that range, but any alpha-numeric combination woulf fail along with "0", "99" etc.
comment Posted December 13, 2007 Posted December 13, 2007 Try: Let ( t = Left ( YourField ; 4 ) ; Exact ( t ; SerialIncrement ( "0000" ; t ) ) )
Tyra Posted December 13, 2007 Author Posted December 13, 2007 Comment, works great! I have never used or even looked at "SerialIncrement" before. Learned something new. Once again thanks for all the help. Time to put this project into production and get some sleep.
Recommended Posts
This topic is 6190 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now