-
-
Couldn't load subscription status.
- Fork 58
Description
When a script is run on the server (PSoS), the plugin intermittently fails to find or read a PDF file that was just created by the Save Records as PDF script step. The failure is not consistent; sometimes the entire script works perfectly.
Environment
- FileMaker Server: 21.1.1
- Server OS: Windows Server
- Plugin: BaseElements 4.2.6
The Goal & Workflow
A script running via Perform Script on Server (PSoS), automates the creation of a single PDF packet.
- It creates a "face page" PDF from a layout.
- It validates that the face page was created successfully.
- It appends multiple receipt PDFs using BE_PDFAppend.
When it fails:
- The Save Records as PDF step reports no errors (Get(LastError) is 0) and the PDF file is created successfully in the Documents folder.
- The script then immediately calls BE_PDFPageCount to validate the new file.
- This function returns a ?, causing the script to halt before it can append any other documents.
Troubleshooting Already Performed
Our efforts have focused on what seems to be a classic race condition, but the problem persists.
- Path Formatting: We've ensured the file paths are correctly formatted for both FileMaker's Save Records as PDF step and the BaseElements plugin functions.
- Wait Loop: To handle potential timing issues, we implemented a robust wait loop that pauses and re-checks for the file for up to 5 seconds. The script still fails intermittently, even with this wait loop in place. Sometimes the file is found immediately; other times the loop times out because BE_FileExists consistently fails to see the file.
Code snippet
# This step always appears to work successfully.
Save Records as PDF [ ... ; $facepage_filepath ; ... ]
# Convert path for the plugin
Set Variable [ $plugin_filepath ; Value: Middle ( $facepage_filepath; 2 ; 999999 ) ]
# This loop is intended to prevent a race condition, but the script still fails sometimes.
Set Variable [ $counter ; Value: 0 ]
Loop
Exit Loop If [ BE_FileExists ( $plugin_filepath ) = 1 ]
Exit Loop If [ $counter > 25 ] // Wait up to 5 seconds
Pause/Resume Script [ Duration (seconds): .2 ]
Set Variable [ $counter ; Value: $counter + 1 ]
End Loop
# On a failed run, this function returns '?' and stops the script.
# On a successful run, it returns the page count and everything proceeds.
Set Variable [ $page_count ; Value: BE_PDFPageCount ( $plugin_filepath ) ]
If [ IsEmpty ( $page_count ) or $page_count = "?" ]
Exit Script [ Text Result: "ERROR: Failed to validate the face page." ]
End If
What could cause such an intermittent failure with this specific combination of FileMaker Server and plugin versions? Since a 5-second wait loop isn't enough to guarantee success, we're looking for other possible causes. Could things like server load, disk I/O contention, or other system processes be intermittently locking the newly created file long enough to prevent the BaseElements plugin from accessing it?
Thank you in advance for any insight you could provide.