1 2 Previous Next 22 Replies Latest reply on Dec 7, 2016 11:45 AM by philmodjunk

    Save and Insert PDF in Remote User record

    ezeitgeist

      Goal:

      Allow me to Create User-specific PDFs and Insert them into the User's PDF Container with a click of a button.

       

      What I am working with:

      There is a Table of "Connections" specific to each User, related by UserID.

      There is a User Table serialized by UserID, as well.

      I have already created a button where Users can request a PDF (labels) creation, which is logged in a Table ("Labels_Request") with Label_Request_IDs and submitted UserID; the active requests show up in a portal when LabelRequest_completed does NOT equal "1".

      The labels are pulled from a Table of ALL Contacts. (Hierarchy: Users --> Connections --> Contacts)

      "Labels by Contact" is a "Printer" layout

      There is a layout that is based in the User Table that just has a single Interactive PDF Container.

       

      Below is my script that I have running from a button within a portal row in the Label Queue layout in the Users Table that only I have access to.

      Screen Shot 2016-12-05 at 8.16.33 PM.png

       

      I am getting errors all over the place when I try to run it.

       

      What am I doing wrong? Should I somehow be using a Related Record command in there? I feel like I'm over-thinking this. I've been trying to figure it out for a couple of hours and I think I've reasoned myself into a super confusing place.

       

      PS Why am I doing this? Because I am running WebDirect for my Users and I do not have the ability to setup a robot with my current setup.

        • 1. Re: Save and Insert PDF in Remote User record
          philmodjunk

          Line 4 makes no sense. The quick find expression is set up incorrectly and then any results of that find appear to be ignored as you perform the quick find and then change to a layout based on a different table occurrence and thus any found set that the quick find produced is not the found set you'd have on the next layout.

           

          Perform QuickFind expects a text calculation whose value is used as criteria for the quick find. The expression:

           

          Users By gSession 10::UserID = $$LabelUserID

           

          is a Boolean expression. It will evaluate as either True (the number 1) or False (the number 0). Thus this expression can only find records in "Users By gSession 10" where UserID is either 1 or 0 depending in how this evaluates. Then this result is ignored by your script. Performing a regular, scripted find, not a quick find using $$LableUserID as your criteria would be faster and make more sense.

           

          Line 6 has a similar problem as it's using a Boolean Expression instead of just searching the Connections table for a specified UserID. And again, after performing the find, the script just changes layouts without doing anything with the found set.

           

          And there are more problems with the rest of your script. I suggest that you start by researching both Perform QuickFind and Perform Find in FileMaker help to better understand how to use them.

           

          Your steps for saving the PDF and inserting it into a container field look essentially correct, but your code just isn't finding the correct records for creating the PDF nor for finding the correct record into which to insert that PDF.

          1 of 1 people found this helpful
          • 2. Re: Save and Insert PDF in Remote User record
            ezeitgeist

            I will research. I had Perform Find expressions but then I thought I was wasting lines and that QuickFind did the same thing. I was apparently horribly wrong. I did not know the Boolean aspect to the QuickFind (I was thinking that it specified the Field to do the Find and then did it based on the criteria). Will make changes and resubmit in hopes I did it more correctly! Thank you for the feedback!

            • 3. Re: Save and Insert PDF in Remote User record
              ezeitgeist

              Okay, updated with proper Perform Finds and added in a related record. I got two errors (new script, then error messages below):

              Screen Shot 2016-12-05 at 10.38.02 PM.png

               

              Screen Shot 2016-12-05 at 10.36.44 PM.png

              Screen Shot 2016-12-05 at 10.36.55 PM.png

              • 4. Re: Save and Insert PDF in Remote User record
                philmodjunk

                Clearly, the error happens at step #16, but that error indicates that it can't find the file just created using the same path variable in line 10. I'm guessing here that line 10 failed to produce a PDF due to an empty found set. You might either put a pause just before line 10 or step through this script in the script debugger to check and see if that's the case. Go To Related records may not be matching to any records and if that's the case, Your script never makes it to the "Labels by Contact" layout.

                 

                While your scripts to find records are less confused, it's not clear to me why you are performing a find and then using Go TO Related records followed by Find Matching records in order to get a set of records for your PDF. After reading your original post yet again, it is just not clear as to how your table occurrences are related to each other. A screen shot of the relevant table occurrences with info as to which of your layouts and your portal are based on which table occurrence might clear that up.

                1 of 1 people found this helpful
                • 5. Re: Save and Insert PDF in Remote User record
                  ezeitgeist

                  Screen Shot 2016-12-06 at 11.32.04 AM.png

                  Users are related to Connections by UserID.

                  Contacts are related to Connections by ContactID and can create records in Connections.

                  Within the Contacts layout, Users (through globals on a pop-over) can create new Connections with a contact.

                   

                  When I tested making a PDF on my own (which, phil, you helped me with ... Filtering printed label (report)? ), The easiest route seemed to be a "Go to Related Records" and then "Find Matching Records [Constrain]" using the Contacts table as the main table for the labels and the Matching records associated with the UserID in the Connections table.

                   

                  From there I just aimed the script to temp save the pdf and place it in that User's PDF container, and then go back to my labels request layout and mark that request completed. The idea was that once I got this figured out, I could add to the script to make it loop back and complete all waiting requests with a click of a button (but, one step at a time).

                  • 6. Re: Save and Insert PDF in Remote User record
                    philmodjunk

                    In your first two script steps, you refer to a TO named "Labels_request". I don't see it in your screen shot. And recall that I asked for more than the screen shot. What layout are you on at the start of this script? On what TO is it based? You mentioned a portal on what TO is the portal based?

                     

                    Did you try using the script debugger or a pause to see if you have any records in your found set at the time you save the PDF?

                    1 of 1 people found this helpful
                    • 7. Re: Save and Insert PDF in Remote User record
                      ezeitgeist

                      Screen Shot 2016-12-07 at 11.40.33 AM.png

                      My apologies. Starts on a Users by gSession 10 layout that only I, the admin, have access to. That layout consists solely of a portal of all the uncompleted Labels_Request requests.

                       

                      The initial script steps store the information from the portal row about the request by the remote User, then is supposed to go to the Connections layout, to input the remote User's ID so that it can next go to the Contacts layout and apply the Find Matching Records [Constrain], constraining to the remote User's ID records. Maybe I do not need to go to the Connections layout, but can just set the field directly without going to that layout first. I just realized that.

                       

                      I will do a script debugger now of the script.

                      • 8. Re: Save and Insert PDF in Remote User record
                        ezeitgeist

                        I made change to Set Field [ Connections by UserID 10:: UserID; $LabelUserID ] instead of going to the layout and doing the Perform Find.

                         

                        I ran the script and still got the same error.

                         

                        When I put in a pause after line 8, there is no constrain. I am getting every record in Contacts.

                         

                        That said, I still get the same error. The Labels.pdf file is not being created. It has to be something wrong with the Saving PDF in a temp path lines. I have never used the Get (TemporaryPath) feature, just read up on it and followed other community threads that I found.

                        • 9. Re: Save and Insert PDF in Remote User record
                          philmodjunk

                          Please answer my questions about layouts, portals and their table occurrences. I need that info to fully understand your script..

                          • 10. Re: Save and Insert PDF in Remote User record
                            ezeitgeist

                            Let me know what I did not answer. I made two replies, the first one addresses an updated TO graph and I thought answered the questions you asked. Let me know what I missed and I will answer ASAP.

                            • 11. Re: Save and Insert PDF in Remote User record
                              philmodjunk

                              Sorry, I saw the screen shot and thought that it was your older post that had a very similar screen shot. To clarify what you want, you want to be able to save a pdf of the users's contacts and insert it into a container field where the user can see/export that PDF file.

                               

                              reading your script, on line 6 you should get a found set of just the connections for the user whose ID was set into a variable on line 1. You then use Go To Related records to get a found set of contacts. But, because you are on Connections and have not used the "match found set" option, you should only see at that point, the contacts for a single connection out of the found set produced on line 6. If you had selected that option here, I would expect to see just the contacts for a given user and there would be no need for any "find matching" to constrain the found set.

                               

                              I made change to Set Field [ Connections by UserID 10:: UserID; $LabelUserID ] instead of going to the layout and doing the Perform Find.

                              That makes no sense and I don't know where in the script you did this, nor why.

                              1 of 1 people found this helpful
                              • 12. Re: Save and Insert PDF in Remote User record
                                ezeitgeist

                                I got confused on the Set Field [] for a moment. I had changed it back by the time you sent the reply. My bad entirely.

                                 

                                Okay, followed your advice and I now have the correct found set related to the remote User.

                                 

                                However, I still get the same "The file 'Labels.pdf' could not be found ..."

                                 

                                Are my lines 9, 10, and 16 incorrect somehow?

                                • 13. Re: Save and Insert PDF in Remote User record
                                  Stephen Huston

                                  You may need a pause of up to several seconds between the steps creating the PDF and the import of the PDF, to allow the file to actually be written to disk. Try a 10 second pause first to see if that solves it, and, if it works, then you can test shorter pauses to find what's most efficient and still reliable.

                                  1 of 1 people found this helpful
                                  • 14. Re: Save and Insert PDF in Remote User record
                                    ezeitgeist

                                    I threw in an up to 30 second pause and I still get the same error.

                                     

                                    Just in case it matters, I am on FMP 15 Advanced, running it on a Mac. Working with a project on a remote server.

                                     

                                    I also saw that maybe throwing in a"/" in the file path naming would help. It did not.

                                     

                                    I tried Saving PDF to my desktop and that works as a proper saving of the file.

                                     

                                    Screen Shot 2016-12-07 at 1.11.04 PM.png

                                    1 2 Previous Next