Jump to content

Creating unique folders to save a script driven pdf file


Tracy
 Share

Recommended Posts

Hello all,

I need your help debugging a script I created.(Filemaker Pro 11) The premise of the script is create an unique folder with a sub-folder on my "c:" drive and save the current record as a pdf in the sub-folder and save the current record as a pdf. The maybe multiple unique pdf's records being saved to the same sub-folder. I also need the script to over write any existing pdf file with a new one if the pdf file name is the same in the same sub-folder.

Below are the field names included in the script and their definitions:

Main::AA File Path (Text Calculation)= "Dynatect/T&M's/" & Main::AA Product Code & "/PDF/" & Main::AA Quote No & "/" & Main::AA Quote No & "-" & If(Main::AA Quote Rev="";"";Main::AA Quote Rev & "-") & Main::AA Quote Line No & ".pdf"

Main::AA Quote No (Text Field)

Main::AA Quote Rev (Text Field)

Main::AA Quote Line No (Number Field)

 

The dreaded script structure that is giving me problems:

image.png.e20fa727cac04de5885b03499ebefd5e.png

 

When I run the script, I'm getting the following error:

F.JPG.72087c77711fb25ae2c25d7518f629d3.JPG

 

The premise of this script and what I need it to do:

New Folder/Record:

1. Create a new folder & sub-folder based on the field above "Main:: File Path" when it's brand new record.

2. Save the current record only as a pdf into the subfolder. If I have multiple records with the same "Main::AA Quote No" & "Main::AA Quote Rev" but a unique "Main::AA Quote Line No", I need these records to saved in the same sub-folder. 

3. Open the current pdf in my adobe pdf viewer and bring the pdf to the top for viewing (for proofing purpose).

Existing Folder/Record:

1. If the folder & sub-folder already exist, I would just like to over ride the existing pdf file within the existing folder and sub-folder with the updated/current pdf record.

2. Open the pdf in my adobe pdf viewer and bring the pdf to the top for viewing (for proofing purpose).

 

Based on the script steps above, it currently/does create the folder & sub-folder but not the pdf file with in the sub-folder. There are no container fields

on the layout to deal with, only a couple calculated text fields. Below a couple of screen shots:

pdf file layout example:

image.png.33567fbe2ca936a4b3d24fd48ac7563c.png

Folder path example:

V.JPG.fd6ffb7b09a08b43d3e80a3b1d16ff9c.JPG

 

Sub-Folder Path with pdf file example:

image.png.616fe234d1869ae01e23f228bc4e7168.png

 

I hope I explained this enough for what I need. If I'm setting this up wrong or if there is a better way of doing this, I'm open to other options.

Thanks,

Tracy

Link to comment
Share on other sites

You are passing the file path including the filename to the md command (AA File Path). Won't that create a folder with the name of the file at that location, like a folder called "RA-87060-1.pdf"? Then that folder is blocking the creation of the actual pdf document.

Link to comment
Share on other sites

Correct. the current script does create the folders and sub-folder fine but the actual pdf record isn't being created. Not sure what you mean by that the folder is blocking the creation of the pdf record?

Could you show me what my script should be written as? I'm open at this point to any changes.

Thank you!

Link to comment
Share on other sites

According to your description your are using the "Send Event" to execute the "md" command with the parameter "c:\...\Desktop/" & AA File Path.
That would be something like
md "c:\...\Desktop/.../PDF/RA-87060/RA-87060-1.pdf"

This would create another folder(!) called "RA-87060-1.pdf" inside the "RA-87060" folder. FileMaker cannot create the actual pdf file by that name if a folder with the same name already exists. Do you see that pdf folder after your test run or did I understand your description wrong?

Link to comment
Share on other sites

"This would create another folder(!) called "RA-87060-1.pdf" inside the "RA-87060" folder. FileMaker cannot create the actual pdf file by that name if a folder with the same name already exists. Do you see that pdf folder after your test run - YES!!😀 or did I understand your description wrong?"

Yes, the current script as it's setup now, does create the main and sub folders. But it doesn't create the pdf file. After some testing, I do see then when I manually save the pdf file into the sub folder. Then I changed some of the field(s) content from the first saved file then re-run the script, the script run correct by not creating any new main and sub folder but just replaces the existing pdf file with the updated one. So issue I'm seeing is the initial creation of the pdf file itself. Will you or anyone be able to test my script steps and find out why the initial pdf isn't being created?

Thanks

Link to comment
Share on other sites

MaxB,

I see what you are saying and the answer is NO. The "Send Event" is not creating another sub folder (RA-87060-1.pdf) within the new sub folder. The issue; after some testing, the creation and saving a new pdf file into the sub folder. Obviously I have an incorrect setup in my script but can't figure what or where.

Thanks

Link to comment
Share on other sites

It may be a timing issue. The "Send Event" sends off a command that runs parallel to the FileMaker script. Maybe the folder is not created fast enough before FileMaker tries to save the PDF into it. Try inserting something like
 
Pause/Resume Script [ Duration (seconds): 3 ]

after the Send Event.

By the way, all this wouldn't be an issue in the current version of FileMaker. "Save Records as PDF" can create the missing folders on it's own for some time now.

Link to comment
Share on other sites

I've tried the Pause/Resume Script and still pops up the error. I've even increased it to 30 seconds and still got the same error. I'm thinking it has to do with Set Variable step in my script:

F.JPG.3ab4ef98ca4427c2044066bf2f246a01.JPG

Main::AA File Path (Text Calculation)= "Dynatect/T&M's/" & Main::AA Product Code & "/PDF/" & Main::AA Quote No & "/" & Main::AA Quote No & "-" & If(Main::AA Quote Rev="";"";Main::AA Quote Rev & "-") & Main::AA Quote Line No & ".pdf"

I've also tested by removing all of the fields in the "Main::AA File Path" and replaced them with my current test record information, which modified the Main::AA File Path to:

Main::AA File Path (Text Calculation)= "Dynatect/T&M's/GC/PDF/RA-87060/RA-87060-1.pdf"

This didn't work either.

Link to comment
Share on other sites

Sorry, I'm at a loss. Following your description my system behaves differently. Setting the variable like you wrote and running the Send Event

Set Variable [ $filepath ; Value: "Dynatect/T&M's/GC/PDF/RA-87060/RA-87060-1.pdf" ]
Send Event [ “aevt” ; “odoc” ; "cmd /c md " & Quote ( "c:\Users\Test\Desktop/" & $filepath ) ]

it creates this folder structure:

fm-folder.png.08c8a8c121b0b0625ccdea7fdf6debee.png

and this won't work as I said before. You'd have to set the path to "Dynatect/T&M's/GC/PDF/RA-87060/". Maybe it's your OneDrive setup but I don't really think so (have you tried a regular, not synced location?).

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Who Viewed the Topic

    1 member has viewed this topic:
    jonx 
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.