malagasy Posted January 3, 2007 Posted January 3, 2007 Is there a script or set of options that allow me to Save a Records as PDF with a specific file name? I would also like the file to go in a specific folder ? What kind of line should I include in my script ? For example, when I create an invoice, I want the file name to be the invoice number from the InvoiceID field and that file to go to my Invoice folder... Thanks for your help !!!
LaRetta Posted January 3, 2007 Posted January 3, 2007 You can use variables to name files and even specify their paths. I store default paths in Preferences file and load my global variables in starup script (with platform and path) but here's example of generic, storing to desktop: Set Variable [ $platform ; Case ( PatternCount ( Get ( SystemPlatform ) ; 1 ) ; "filemac:" ; "filewin:") ] Set Variable [ $path ; Get ( DesktopPath ) ] Set Variable [ $FileName ; InvoiceNumber & ".pdf" # Then combine them into one string Set Variable [ $FullPath ; $platform & $Path & $fileName ] # Then save your file Save Records As PDF [ Restore, no dialog; $FullPath; Records being browsed ]
malagasy Posted January 3, 2007 Author Posted January 3, 2007 I'm totally new to the whole scripting and don't really understand what I do. Here is the script I have in place: Go to Layout ["Invoice Layout" (Invoice)] Set Variable [ $platform ; Case ( PatternCount ( Get ( SystemPlatform ) ; 1 ) ; "filemac:" ; "filewin:") ] Set Variable [ $path ; Value:Get ( DesktopPath ) ] Set Variable [ $FileName ; Value:Invoice::InvoiceID & ".pdf" Set Variable [ $FullPath ; Value:$platform & $Path & $fileName ] Save Records As PDF [ Restore, no dialog; $FullPath; Records being browsed ] When I run the script, I have the following Error message 392934.pdf could not be created on this disk. Use a different name, make more room on the disk, unlock it or use a different disk What am i doing wrong ?
LaRetta Posted January 3, 2007 Posted January 3, 2007 I can't say - I've never received that error. Open Data Viewer and run debugger on it. What does it show as $FullPath? Are there any invalid characters, such as />"? Do you have pdf installed on that system? Everyone should have privileges to save to their desktop.
LaRetta Posted January 3, 2007 Posted January 3, 2007 To clarify, that error usually indicates a file is read only; readily obtained when one saves a file on CD. But you are creating a file so it makes little sense. The error indicates you can't save to your local hard disk and that doesn't make sense either.
malagasy Posted January 3, 2007 Author Posted January 3, 2007 I really don't get it...can someone help with what I have to do in details ? Thanks
comment Posted January 3, 2007 Posted January 3, 2007 that error usually indicates a file is read only It could also indicate that the specified directory does not exist.
malagasy Posted January 3, 2007 Author Posted January 3, 2007 how do i specify the directory then ? I assume it is in the Path line but how ? In that line, I chose Set Variable. the options came up and I typed $Path for the Name Get ( DesktopPath) for the Value 1 for the Repetition Do I have to specify the directory path in the value ? if so, how ?
LaRetta Posted January 3, 2007 Posted January 3, 2007 (edited) Thanks, Michael. Okay, try this: Create a global text field. Disable to Save to PDF line and add this: Set Field [ thatGlobal ; $FullPath ] Then copy/paste the line [color:green]data value in the field here for us to see. [color:green]Your script is a copy/paste of mine. I doubt your script looks exactly the same? Something is off somewhere because Get(DesktopPath) should work and Windows always has a desktop path folder. Edited January 3, 2007 by Guest Added green
LaRetta Posted January 3, 2007 Posted January 3, 2007 I re-created your error. Yes, there is something probably wrong with the Directory name. I have never known Windows not to find its desktop. Are you appending to add a sub-directory? If so, the directory name must end with / and that might explain the problem.
malagasy Posted January 3, 2007 Author Posted January 3, 2007 I think it gets kinda funny...guess what guys ? After all the good advices you guys gave me, I decided to restart my computer and the script works I WILL NEVER GET COMPUTER. However, I need your help on 2 more thing, the script will save the PDF file on desktop...I'd like to save it on D:BusinessInvoice How do i do this ? Then, the script is for a button on a portal included in the customer layout and i want the script to make the invoice for the specific portal record...what line of script should i include ?
LaRetta Posted January 3, 2007 Posted January 3, 2007 D:BusinessInvoice You can read up on it in help. Your string will need to look something like: filewin:/D:/Business/Invoice/InvoiceNumber.pdf Again, I wouldn't hardcode the path but store it as data and load global variable at startup then reference it via script as needed. In this way, if you change the folder name or location, all your files will store consistently in same place and you won't be modifying all your scripts. Script on button in portal row would look something like: Freeze Window Go To Related Record [ Show only related records from Invoices using Invoice layout ] ...your pdf script portion Go To Layout [ original layout ]
mr_vodka Posted January 3, 2007 Posted January 3, 2007 Just change the value of the variable from the Desktop Path function to your directory that you want. Set Variable [ $platform ; Case ( PatternCount ( Get ( SystemPlatform ) ; 1 ) ; "filemac:/" ; "filewin:/") ] Set Variable [ $path ; "D:/Business/Invoice/" ] Set Variable [ $FileName ; Value:Invoice::InvoiceID & ".pdf" Set Variable [ $FullPath ; Value:$platform & $Path & $fileName ]
comment Posted January 3, 2007 Posted January 3, 2007 I am not sure the 'filemac/filewin' part is required when saving a file. A path defined as: Get ( DesktopPath ) & "/" & Table::Filename & ".pdf" works just fine for me. Also, I don't quite see the advantage of assembling the path piecemeal, with intermediate variables. As LaRetta says, I would put the path to the directory in a global field, then: Set Variable [ $path ; Table::gPath & Table::Filename & ".pdf" ] Save Records as PDF [ File Name: “$path”; Current record ]
mr_vodka Posted January 3, 2007 Posted January 3, 2007 No arguement here. I completely agree with you and would also use a global field to store the path as well. When I posted, I had not seen Laretta followup post. I was just trying to display it for malagasy to see that the path can just be easily changed if he didn't want to use Get ( DesktopPath ); still using the steps in Laretta's first post. As for not using 'filemac/filewin', he should use it because he isnt using Get ( DesktopPath ), no?
comment Posted January 3, 2007 Posted January 3, 2007 As for not using 'filemac/filewin', he should use it because he isnt using Get ( DesktopPath ), no? I don't think so. The result of Get ( DesktopPath ) does not include 'filemac/filewin', so using it or not should not matter. I think the distinction between 'filexxx:', 'imagexxx', 'moviexxx' may be significant when bringing files into Filemaker, but not in the opposite direction.
comment Posted January 3, 2007 Posted January 3, 2007 Try inserting QuickTime into a container and check the resulting path.
Genx Posted January 3, 2007 Posted January 3, 2007 Cool! I hope they add support for additional movie formats i.e. mpeg... in fm9 -- though i suppose you could get away with using the webviewer..
comment Posted January 3, 2007 Posted January 3, 2007 QuickTime can usually play a MPEG movie, at least on a Mac. This is a very complex subject, so let me just say that QT is not really a format - more like a platform. I am not sure Filemaker controls what QT does or doesn't. I think it's an external resource, just like the web viewer.
Genx Posted January 3, 2007 Posted January 3, 2007 Hmmm, I don't like the quicktime software itself the whole paying for standard features that come in the "pro" version kind of puts me off, and I suppose the bigger issue is really that it doesn't ship with windows as standard, I'd prefer that on windows they just used wmp. I wonder if you could get away with just installing quicktime alternative... Which plays all quicktime formats as well as mpegs. Either way, i'll try both quicktime and alternative and see what formats it will .. or won't accept. Thanks for the insight comment.
T Howard Posted January 5, 2007 Posted January 5, 2007 Malagasy, Can you please post the final version of your script that worked? I have tried piecing the posts together for a solution but nothing works.
mr_vodka Posted January 5, 2007 Posted January 5, 2007 In its Simplest form there are basically two steps. Set Variable [ $path ; "filewin:/D:/Business/Invoice/Whatever.pdf" ] Save Records as PDF [ File Name: “$path”; Current record ] However, in the examples that were posted above, it was demonstrating how to do it without hard coding the path or the filename that you want to save the PDF as. You can reference a field for those if you wish.
malagasy Posted January 7, 2007 Author Posted January 7, 2007 (edited) If you need to store the PDF in a specific folder, you need the following line of scripting: Set Variable [ $Path ; "filewin:/D:/Business/Invoices/"] Make sure you don't forget anything such as / ... If you want the file saved to have a specific name, you also need a line such as: Set Variable [$FileName ; Invoice::InvoiceID] Hence, this 2 previous line need another line such as: Set Variable [$FullPath ; $Path & $FileName] At the end your script should look like this > Set Variable [$Path ; "filewin:/D:/Business/Invoices/"] Set Variable [$FileName ; Invoice::InvoiceID] Set Variable [$FullPath ; $Path & $FileName] Save Records as PDF [ “$FullPath”; Current record ] This one works for me, let me know if you have any problems...I can try to help. David Edited January 7, 2007 by Guest
T Howard Posted January 9, 2007 Posted January 9, 2007 Thank you Malagasy and everyone else in this post. My script is now working and I incorporated some of the suggestions regarding global fields.
RT Posted February 3, 2007 Posted February 3, 2007 (edited) hello i am having trouble that has cost me hours, if i use Set Variable [ $path ; Get ( DesktopPath ) ] Set Variable [ $FileName ; InvoiceNumber & ".pdf" i get the errors stated above "cannot write to disk" now if i use any other field to save by it works. i think the problem is with my invoice and purchase order numbers. PO[color:red]:1024 PO[color:red]:1025 PO[color:red]1026 or invoice inv[color:red]:1024 inv[color:red]:1024 so these characters are messing things up because if i pick another field it works, [color:purple]can i escape these characters in the script. Thanks RT Edited February 3, 2007 by Guest
Genx Posted February 3, 2007 Posted February 3, 2007 Set Variable [ $path ; Get ( DesktopPath ) ] Set Variable [ $FileName ; Substitute(InvoiceNumber ; ":" ; "-" ) & ".pdf"
mr_vodka Posted February 3, 2007 Posted February 3, 2007 "filewin:" & Get ( DesktopPath ) & invoice::filename & ".pdf" is what you want to use, but because of the colon, you are only going to be able to get files called PO or INV. The rest of the fiel name will be chopped off. Do not use the colon because it means something in paths. Try the underscore _ instead.
RT Posted February 3, 2007 Posted February 3, 2007 thank you both for your answers. i went with Genxs solution and it works.
1Adam12 Posted April 6, 2007 Posted April 6, 2007 it's important to remember that the path parsed by Filemaker must use "/" as the delimiters for Windows paths and not "". If you are using TRFile for example to capture paths, it will capture using "" and after you capture the path, you should do a Subst on it to swicth the to /. This resolves the 'can't save to disk error', too.
Recommended Posts
This topic is 6833 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