7 Replies Latest reply on Sep 12, 2014 11:52 AM by episking

    Server Side Email with Record Data

    episking

      Title

      Server Side Email with Record Data

      Post

      I have a form that users fill out and click submit.  Currently I have the submit button set to run Script1 which is not a server side-script.  Script1 does the following:

             
      • Commit Records/Requests
      •      
      • SetVariable [$$RecordNumber; Value:Get (RecordNumber)]
      •      
      • Go to Record/Request/Page [No dialog; $$RecordNumber]
      •      
      • Perform Script on Server [Wait for completion; "Script2-ServerSide"]

       

      Script2-ServerSide does the following:

             
      • Go to Layout ["ProperLayoutName" (ProperTableName)]
      •      
      • Go to Record/Request/Page [No dialog; $$RecordNumber]
      •      
      • Send Mail [Send via SMTP Server; No dialog; To: "recipient@mail.com"; Subject: "New form - " & ProperTableName::Submitter Name & " - " & ProperTableName::Project Name & " - " & ProperTableName::Timestamp]

       

      The email comes through just fine, and it pulls the data, but always from the first record.  I can't seem to figure out how to get the server-side script to pull the proper record's data.  I do have a field named "docKey", that is an Auto-Entered serialized number, non-editable (a primary key, essentially), so I could do a lookup based on that field?

      Open to suggestions to get the proper record's data into the email.

       

      Thank you!!!

      -Eric

        • 1. Re: Server Side Email with Record Data
          philmodjunk

          Get ( recordnumber )

          Returns the position of the record in the current found set. It is not a unique identifier of the record. Get ( Recordnumber ) will return a different value for the same number simply if you have different records in your found set or sort them into a different order.

          What you need to do is capture the value of the record's primary key and send it to the server side script as a script parameter. The server side script can then perform a find for that record and use it as the data source for your email. (I don't believe that a server side script can access the value of a global variable defined on the client machine. You have to think of a server side script as similar to calling across the room to another user and asking them to do a task in filemaker for you, they don't see your found set, variables or global variable values you would have to tell them all of those details--which is why you'd use a script parameter to send that info to the server side script.)

          Caulkins Consulting, Home of Adventures In FileMaking

          • 2. Re: Server Side Email with Record Data
            episking

            Is there a way to pass a variable from client to server-side?  <---  Script parameter.  Got it.  I'll do some digging.

            Thanks for your consistently quick and helpful feedback!  I really appreciate it.

            -EP

            • 3. Re: Server Side Email with Record Data
              episking

              Ok, so I have my Script1  edited to:

                     
              • Commit Records/Requests
              •      
              • Perform Script on Server [Wait for completion; "Script2-ServerSide"; Parameter: ProperTableName::docKey]

               

              And my Script2 is edited to:

                     
              • Go to Layout ["ProperLayoutName" (ProperTableName)]
              •      
              • Perform Find[Restore]  (where the find request criteria is: ProperTableName::docKey: [== Get (ScriptParameter)]
              •      
              • Send Mail [Send via SMTP Server; No dialog; To: "recipient@mail.com"; Subject: "New form - " & ProperTableName::Submitter Name & " - " & ProperTableName::Project Name & " - " & ProperTableName::Timestamp]

               

              This returns an empty email...  Am I on the right track?

               

              Thanks!

              -EP

              • 4. Re: Server Side Email with Record Data
                philmodjunk

                Store find criteria cannot evaluate calculation expressions.Your find is looking for the exact value of "Get ( ScriptParameter)" not the Value of the script parameter.wink

                So do it this way:

                Enter find mode [] ---> clear the pause
                Set FIeld [ ProperTableName::DocKey ; "==" & Get ( ScriptParameter ) ]
                Perform FInd [] ---> note no criteria stored here.

                Not only does the "set field method" enable you to use calculations, it leaves all the criteria visible in your script. You don't have to double click and open other dialogs to see what criteria is specified.

                For more scripted find examples, see: Scripted Find Examples

                Caulkins Consulting, Home of Adventures In FileMaking

                • 5. Re: Server Side Email with Record Data
                  episking

                  Thank you kindly!!  Is there a way to get filemaker to compose HTML email?

                  -EP

                  • 6. Re: Server Side Email with Record Data
                    philmodjunk

                    Take a look at email plug ins. I believe that there are several that can do that. Don't know how/if that'll work "server side"...

                    • 7. Re: Server Side Email with Record Data
                      episking

                      Ok.  Thanks a ton.

                      -EP