1 2 3 Previous Next 30 Replies Latest reply on Jun 18, 2014 11:50 AM by briancrockett

    email script problem

    TodPoirier

      Title

      email script problem

      Post

           I am working on setting up a button to send email to people when a trouble report is created inside our inventory database we've created with FMP 13.  I've created a calculation that I've been trying to implement both through a new field or thru the emails message calculation option.  When I view the results of the calculation within the database itself it gives me the data I expect, but when the calculation is used within the body of an email I get the text I've set up inside the calculation but not the data stored in the fields.  My calculation is as follows, what do I have wrong?:

           "Trouble report creation by:"  &  " "  & Trouble Reports::Reported By  &  " " & "on"  &  " "  & Trouble Reports::Date Created  &  ¶ &
           ¶ &
           "The trouble is in: "  &  " "  &  Trouble Reports::Department  & ¶   &
           "In room: " & Trouble Reports::Room  & ¶ &
           ¶ &
           "With equipment: "  & " " & Trouble Reports::Equipment  & ¶&
           ¶ &
           "Problem is:"  & " "  & Trouble Reports::Problem Type  & ¶ &
           ¶ &
           "Reporter notes: " & " " & Trouble Reports::Reporter Notes & ¶ &
           ¶ &
           "Action taken: "  & " "  & Trouble Reports::Action Taken

        • 1. Re: email script problem
          briancrockett

               You haven't given much information. However whenever I have a problem where data isn't showing up I start by checking the context.

               When the script runs, what layout is displayed?  The table associated to the layout must be one that is referenced in the calculation. For example table "Trouble Reports::" must be associated to the current layout or be related to that table.

               In other words if the layout table is "Inventory::" and you run a script with calculations for table "Trouble Reports::" it won't work. Your script must switch to a layout connected to table "Trouble Reports::" and then find the correct trouble report before the calculations will work. 

          • 2. Re: email script problem
            TodPoirier

                 The button is on the Trouble Report Layout and everything referenced is in the same layout. 

                 I've discovered through trial and error that if I put my calculations right in the button as part of the "send mail" setup I can get the results I'm looking for.  If, however, I write the script externally and tell the button to run that script I don't get the data from the fields.  I'm a bit unsure why this might be?

            • 3. Re: email script problem
              philmodjunk

                   Assuming that your Trouble Report layout is actually based on the Trouble Report Table Occurrence, perhaps the record that computes the value that you want to see in the email is not the record that is current at the time your send mail script step executes. That would be another example of the "context" issue Brian described in his post.

              • 4. Re: email script problem
                TodPoirier

                     From what I understand we're entering information on the trouble report layout which is based on the single occurrence of trouble report we have in our relationships and the button controlling the script is on that same layout.  Here's a screen shot of what's set up (under revision visually, a couple things are duplicated at the moment)

                • 5. Re: email script problem
                  philmodjunk

                       Another thing to check with the calculation field is it's specified Result Type. The specified result type should be Text, not Number.

                  • 6. Re: email script problem
                    TodPoirier

                         I was able to fix the script by specifying it:  Go to Layout ["Trouble Reports" (Trouble Reports)]

                         For some reason, even though I was calling the script from that layout, it wasn't referencing it.

                    • 7. Re: email script problem
                      TodPoirier

                           I only half fixed it.  Before I press the button in the trouble report I need a way to tell the script to go to the current record.  It's going to the first record.

                      • 8. Re: email script problem
                        philmodjunk

                             That suggests that something is changing the layout and current record on you when you click this button. That might be due to your script tripping a script trigger that then performs a different script that interferes. I need to see your script.

                             To post a script to the forum:

                               
                        1.           You can upload a screen shot of your script by using the Upload an Image controls located just below Post a New Answer.
                        2.      
                        3.           You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here. (with this approach, you can get multiple script steps on the same line, please edit the pasted text by inserting some returns to separate those steps.)
                        4.      
                        5.           If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
                        6.      
                        7.           If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format.
                        • 9. Re: email script problem
                          TodPoirier

                               Here's a sceen shot.  Would it work if I specified "Original Layout" instead of the "Trouble Report"?

                               While I'm at it - the last step in the script, the "Show Custom Dialog" does not work.

                               Also, I'm confused about sending an email to multiple email addresses.  I've come across about three different "solutions" for doing this by putting comma's, semicolons or plus signs between email addresses with different combinations of double quotes and they haven't worked.

                          • 10. Re: email script problem
                            philmodjunk

                                 Do you have any script triggers set up on this layout? (OnObjectExit, OnCommitRecords, Etc...)

                                 Do you have FileMaker Adavanced by any chance?

                            • 11. Re: email script problem
                              TodPoirier

                                   No, no script triggers.

                                   and yes, we have FileMaker Pro Advanced 13

                              • 12. Re: email script problem
                                philmodjunk

                                     Please enable the script debugger and then click this button and watch what happens in the script and on your layout, clicking "step into" to step through this simple script one step at a time.

                                     You shouldn't need to use Go to Layout to go to the layout that you are already on and you shouldn't end up on the first record instead of the current record either.

                                • 13. Re: email script problem
                                  briancrockett

                                       I usually pass the unique Id of the record as a parameter in the button. Then have the script find that unique id before processing anything else.

                                        

                                       Not sure if we're allowed to promote products here, but I really love FmPro Script Diff from .COM solutions. I'm not affiliated in any way with the company but it does a good job with pretty script prints.  It's main purpose is to compare two scripts, but I rarely use it for that. It also produces a really nice script output which is both indented and has commands and comments in boldface.  I use this to document my work. I paste the scripts into a word processor and change the text colour and highlighting to show changes.

                                       Random unsolicited advice for a newbie, Document, Document, Document. Keep files with marked up scripts and calcs, notes with what you did, To Do items marked off, accounts and passwords, procedures for how to use your solution, etc.. I keep note templates that have pre-made tables for "Fields, Tables, TOCs, and Scripts of Interest" , "Fields, Tables, TOCs, and Scripts Changed" and "Fields, Tables, TOCs, and Scripts New" etc. When you come back to your solution after a couple years this will be a treasure trove that will save your job.

                                  • 14. Re: email script problem
                                    philmodjunk
                                         

                                              I usually pass the unique Id of the record as a parameter in the button. Then have the script find that unique id before processing anything else.

                                         Yes, but none of that should be necessary if the user is clicking a button for a script set up to use the current record shown on the layout.

                                    1 2 3 Previous Next