10 Replies Latest reply on Dec 2, 2014 3:15 PM by episking

    Server Script Email Attachment from Container Field

    episking

      Title

      Server Script Email Attachment from Container Field

      Post

      I'm trying to send an email using a server-side script.

      Here's the script:

      You can see that the last step puts the filepath into a field so I can view it.  It shows:  fmwin:/C:/Windows/Temp/S267/AdminLinks.pdf after I run the script.

      Yet no attachment comes through on the email that I receive.

      Untitled.png

        • 1. Re: Server Script Email Attachment from Container Field
          philmodjunk

          Is $$attachpath specified as the attachment in the Send Mail Step? (can't see that detail in your screen shots.)

          While it should work, there's no reason to make this a global variable (Two $$)  that I can see as a global variable set by a PoS script won't be visible to the client anyway. A local variable (one $) should work just as well.

          • 2. Re: Server Script Email Attachment from Container Field
            episking

            Yes it is specified as in the email step.

            I was trying the global variable to see if it would make a difference... I've switched it back to local.

            See the below error I'm getting when I'm trying to run the server-side script.

            • 3. Re: Server Script Email Attachment from Container Field
              episking

              Well, first off, I discovered that I had the Variable set to "Fmwin:" when it should be "filewin:", so I changed that.  I tried running it as a local script and it works (when i change Get (DocumentsPath) to Get (TemporaryPath).  Then I moved back over to the server, and I'm still getting the errors... It appears that the filemaker server or the permission set that the server uses does not have permission to either the DocumentsPath or the TemporaryPath.

              Thoughts?

               

              Thanks for your help!

              -EP

              • 4. Re: Server Script Email Attachment from Container Field
                philmodjunk

                Error Code 3 means "command is unavailable".

                You shouldn't need to use use "filewin:" at all. The first part of your path calculation can just be Get ( TemporaryPath).

                You might try leaving it out and see what happens.

                And Get (DocumentsPath) or Get ( TemporaryPath) should both work when you test this client side.

                • 5. Re: Server Script Email Attachment from Container Field
                  episking

                  When I use Set Variable [$attachmentpath; Get ( TemporaryPath ) & GetContainerAttribute (Purchase_Request::Quote; "filename")] and then Insert Calculated Result [Purchase_Request::filepath; $attachmentpath], the result is: /C:/Windows/Temp/S907/Quote #30556 Win 8.1 Ent Upgrade Lic w SA.pdf, which I believe is an invalid path from filemaker's point of view...  Even still, the issue that I'm seeing is with the Export Field Contents script step.

                  This is a Server Side Script.  Is there any issue using Export Field Contents with a Server Side Script?  Does the user that the filemaker server process uses have to have permissions to the temporary folder?  I don't see any files or folders being created in C:/Windows/Temp when I run the script.  I also changed Get (TemporaryPath) to Get (DocumentPath) to see if it made any difference, and it did not.

                  Thank you for your assistance.

                  Thoughts?

                  -EP

                  • 6. Re: Server Script Email Attachment from Container Field
                    philmodjunk

                    You may need to report this over in Report an Issue to see what the techs have to say about this. I do know of an KnowledgeBase article that describes some pretty severe limitations on server side scripts that import and export, but it's in the context of Import/export RECORDS, not field contents so I don't know that any of that info applies.

                    http://help.filemaker.com/app/answers/detail/a_id/7035/kw/server%20import%20records

                    Ummm, put all that on hold for a moment. Open up your script in the script editor and check server compatibility on all steps. Your Show Custom Dialog step, for example, is not server side compatible. Once you have all such steps removed from your script, see if you still get the same issue just to rule out any issues with incompatible steps.

                    • 7. Re: Server Script Email Attachment from Container Field
                      episking

                      Yes... It appears that filemaker's server-side scripting is not compatible with the Export Field Contents script step...

                      Is there any work around to attach a container object to an email that is sent from the server?

                      I don't want to open up my SMTP server to every user of the form I'm creating, that's why I'm using the sendmail on the server side.

                       

                      Thanks for your help!!

                      -EP

                      • 8. Re: Server Script Email Attachment from Container Field
                        philmodjunk

                        Export the Field Contents client side to a shared directory. Use the server side script to attach from that directory by passing at least the file name to the PSoS as a script parameter.

                        You can use a system script or a plug in to delete the file after exporting and emailing.

                        • 9. Re: Server Script Email Attachment from Container Field
                          episking

                          Nice idea!!

                          The client-side export is functioning correctly through the followng script steps:

                          Set Variable [$$filename; Value: "filewin://server/share/temp/" & GetContainerAttribute (Purchase_Request::Quote; "filename")

                          Export Field Contents [Purchase_Request::Quote; "$$filename]

                          Perform Script on Server [Script; parameter: Purchase_Request::docKey]

                          The server-side script goes to the proper layout, enters find mode, sets field docKey with the passed script parameter, then:

                          Set Variable [$$filename; Value: "filewin://server/share/temp/" & GetContainerAttribute (Purchase_Request::Quote; "filename")

                          Send Mail using SMTP Server, with file attachment set as $$filename

                           

                          Still not working...  The server side script seems to not be able to access the file on the network share?  How would the server access the file?  What credentials would it be using to see that file?  Should the shared folder be on the same server as the filemaker server?  I'm going to try that out... Use the network path for the client, then the local path for the server.

                          -EP

                          • 10. Re: Server Script Email Attachment from Container Field
                            episking

                            Tried using "filewin://server/share/temp/" & GetContainerAttribute (Purchase_Request::Quote; "filename") for the client and "filewin:/C:/temp/" & GetContainerAttribute (Purchase_Request::Quote; "filename") for the server, but still no dice.  Again, client can store no problem, but apparently the server can't read the files to load into the email.