12 Replies Latest reply on May 24, 2010 1:23 PM by Xaqtly

    Help with script triggers inside portal

    Xaqtly

      Title

      Help with script triggers inside portal

      Post

      I get the feeling the solution to this problem is a simple one, I just don't know what it is.

       

      I have a portal on my main database, and it shows records and fields from a related database. One of the fields in the portal is a status field. What I'm trying to do is get it to run a script that sends an email when that status is changed to a specific user through the portal on the main page (as opposed to changing it on the related database).

       

      So far everything is working. I set a script trigger on the status field in the portal to run the "send email" script when a certain user's name is chosen, and it works. However, it only works for the first related record.

       

      In any given job, there will be multiple related records assigned to that job, hence the need for a portal to see them all at once. So in a job with 10 related records, changing the status of the first related record to a certain user will send the email via the script trigger. It doesn't work if I change the status on the second or third or any other record in the portal.

       

      How do I fix it so that changing the status on the thrid (or any other) record will send an email via the script trigger? Or to put it another way, why is the script trigger only affecting the first record in the portal?

       

      Thanks for any help.

        • 1. Re: Help with script triggers inside portal
          philmodjunk

          Which trigger are you using?

          • 2. Re: Help with script triggers inside portal
            Xaqtly

            OnObjectModify.

            • 3. Re: Help with script triggers inside portal
              philmodjunk

              Is this field formatted as a pop-up menu?

               

              Please post the script.

               

              I've used script triggers in portals and they work on all rows of the portal so we need to figure out why it didn't work for you.

              • 4. Re: Help with script triggers inside portal
                Xaqtly

                Ah, good point. The field is formatted as a Drop-down List, and it uses a Value list. The source for the value list is "from another file", namely the value list in the related database.

                 

                Here's the script:

                 

                 

                If [ Elements05::Item Status = "user_name1" ]
                Send Mail [ Send via E-mail Client; To: "xxx@xxx.xxx"; Subject: Elements05::Job # & "." & Elements05::Item # & " has been assigned to you."; Message: Elements05::Job # & "." & Elements05::Item # & " has been assigned to you." ] [ No dialog ]
                Else If [ Elements05::Item Status = "user_name2" ]
                Send Mail [ Send via E-mail Client; To: "xxx@xxx.xxx"; Subject: Elements05::Job # & "." & Elements05::Item # & " is back for re-work."; Message: Elements05::Job # & "." & Elements05::Item # & " is back for re-work." ] [ No dialog ]
                End If

                 

                 


                • 5. Re: Help with script triggers inside portal
                  philmodjunk

                  One observation, with OnObjectModify, if you type in your drop down's field, this trigger will fire with each and every key stroke. That's why this can be a better trigger for a pop-up menu. For drop downs, OnObjectExit may give you more predictable results.

                   

                  Is Elements05 the table occurrence your portal is based on? (Did you select Elements05 in the show records from box in portal set up?)

                  • 6. Re: Help with script triggers inside portal
                    philmodjunk

                    This is a case where filemaker advanced saves a lot of frustration. IF you had that version, I'd suggest enabling the script debugger and watching it execute when you edit the field. This would very likely pinpoint for you where your script is going wrong.

                     

                    Since you don't, you may have to modify your script to investigate further. You could put Show Custom Dialog [Quote ( Elements05::Status )] at the start of this script as a test. Then edit the field in different rows of your portal and see what pop's up in the custom dialog. The quote function will enclose the field's contents in quotation marks which can make it easier to spot invisible characters such as a space or carriage return that might be affecting your script's behavior.

                    • 7. Re: Help with script triggers inside portal
                      Xaqtly

                      I tried OnObjectExit first, but it was generating two emails each time I changed a status, instead of one. OnObjectModify seemed to fix that. I wondered if it was generating two emails because there were two exits - exiting the field and exiting the portal. I dunno. Yes, Elements05 is the related database it's pulling the information from.

                      • 8. Re: Help with script triggers inside portal
                        Xaqtly

                         


                        PhilModJunk wrote:
                        You could put Show Custom Dialog [Quote ( Elements05::Status )] at the start of this script as a test.

                        I did that, and when I change the status of any record other than record #1, that dialog box shows the status to be the same as record #1, no matter what it is. it's like the script thinks all the records are the first record.

                         

                        • 9. Re: Help with script triggers inside portal
                          philmodjunk

                          Which explains why this is happening--at least it rules out the script trigger as the issue.

                           

                          Is the field you've set the trigger on really from Elements05 and not some other table occurrence? Double click it while in layout mode and check.

                          • 10. Re: Help with script triggers inside portal
                            Xaqtly

                            Ah, it looks like it's another... occurance? Sorry, I didn't build this database. It was built a long time ago, and I sort of inherited it when I started working here, and I've been trying to learn Filemaker along the way.  :D 

                             

                            Here's what the portal is pulling records from: Elements05 is the name of the database, but the portal is set to show records from Elements05 2 which appears to be another occurance, set up with a relationship to Elements05 via one of the fields. So I don't know why the portal is pulling from the second occurance and not the main table, but this is a big complicated database and I don't understand Filemaker well enough to understand how it all works together.

                             

                            I am scared to change the portal so it pulls from the main table because I don't know what effect that would have on the data, and this is a critical database, all our work is done in it.

                            • 11. Re: Help with script triggers inside portal
                              philmodjunk

                              Don't change your portal. Change your script to reference values from Elements05 2 instead of Elements05 as it does now.

                               

                              If you search Manage | Database | Relationships carefully, you should find that you have a table occurrence labeled Elements05 and another labeled Elements 05 2. Each potentially defines a different relationship by linking different table occurrences or by using different pairs of match fields. Analyzing the diffeerences here may help you better understand how the database works.

                               

                              • 12. Re: Help with script triggers inside portal
                                Xaqtly

                                That was it, I feel like an idiot, and thank you. :smileyvery-happy: