5 Replies Latest reply on Nov 20, 2014 11:25 AM by philmodjunk

    Script Trigger not firing

    FilmUser

      Title

      Script Trigger not firing

      Post

      Windows 7, FMP and Server 12

      Three fields: two are text, with the same drop down value list, Creating Engineer and Lead Engineer. The Lead Engineer is a lookup field set to lookup from the Creating Engineer. Third field is the Record_ID.

      When a record is created, the Creating Engineer is selected from the drop down. In almost every case, the Lead Engineer will be the same, so I want to lookup the Creator to populate the Lead. The lookup works when the Creator is populated the first time, but not when changed, so I wrote a script.

      Script has one step - Relookup field contents, referencing a self relationship to the Record_ID.

      The script works fine when executed manually.

      The script trigger is set to the Creating Engineer field, "On Object Save", which I've used with scripts many times, except in this case nothing happens when changing the selection in that field. After choosing from the drop down, FMP just goes to the next field in the tab order.

      What am I missing?

        • 1. Re: Script Trigger not firing
          SteveMartino

          If you click outside of any field and save the record, does it change?  Try changing it to OnObjectModify

          • 2. Re: Script Trigger not firing
            philmodjunk

            The first thing that you are missing is: "The lookup works when the Creator is populated the first time, but not when changed"

            That should not be the case. If you select a new value in the creator field, the lead engineer field should automatically update without relying on a script to do so. I suggest that you review the design details of this part of the system to see why it isn't working.

            My guess is that even with this change, your "look up" still looks up the same value and thus no change appears in the lead engineer field. Thus your script trigger performed script also looks up the same value and appears not to work.

            As a test, either enable the script debugger (if you have FileMaker Advanced), or insert a Show custom dialog step into your script before once again trying to trip the script trigger as a way to confirm whether or not your script is actually working.

            Hmm, just had a thought; Add a commit records step to the beginning of this script and see if that enables it to correctly look up a different value in the field.

            • 3. Re: Script Trigger not firing
              FilmUser

              I have clicked outside the field, I'm never sure when saving occurs, it's just always worked for me.

              And yes, I tried On Object Modify, On Object Keystroke, and On Object Exit. Nothing happens to the Lead field, it retains the original value from the first lookup.

              • 4. Re: Script Trigger not firing
                FilmUser

                I tried both, dialog and commit record, and it worked. Then I took out the dialog step, and the script still worked.

                Thanks much, Phil, as always. But I don't understand why I needed to do this, and the script is still needed to update the Lead field. Does it have something to do with the drop down lists (or the fact that both fields use the same one?) I don't see anything in the field definition of the look up - I did try unchecking the "don't copy if empty" box, but I still need the script to update Lead.

                • 5. Re: Script Trigger not firing
                  philmodjunk

                  Commit Records saves the current record's data back to the database file and this is often necessary to get related data to re look up. Clicking the layout back ground is a manual way to commit records.