1 2 Previous Next 22 Replies Latest reply on Aug 20, 2016 11:12 AM by philmodjunk

    Script runs into indefinite loop when script triggered

      Hi ,

       

      I want to implement a simple autotext-fiunction in a textfield that can change shortcakes like "[kr]" into "Kind regards".

       

      For that I have made a script that writes into the requested textfield this changes.

       

      Variable setzen [ $Mailtext ; Wert: Mails::Mail_Text ]

      Variable setzen [ $Mailtext ; Wert: Austauschen ( $Mailtext   ; "[kr]" ; "Kind regards," ) ]

      Feldwert setzen [ Mails::Mail_Text ; $Mailtext ]

       

      This script get started by the script event "Change Field" of the Field (do not know the exact English term as I use a German version).

       

      If I leave the field the changes are made, but then the whole database is not usable any more as it seems to run into an indefinite loop.

       

      Any ideas?

       

      Btw: I want to have a whole list of shortcode and also translations into different languages. This would be stored best in a table itself like ID, shortcake, translate2German, tanslate2English..

       

      Any suggestions how do use these n shortcakes dynamically in such a script?

       

      Best,

       

       

       

      Aktuelles Script verlassen [ Ergebnis: Hole ( ScriptName ) ]

        • 1. Re: Script runs into indefinite loop when script triggered
          Mike_Mitchell

          Just those three script steps wouldn't cause a loop. I suspect you have a trigger repeatedly firing. Typically, this is caused by the triggering event causing a script to run that also triggers the same event. I suspect your Set Field script step is the culprit. If you have an OnObjectModify or OnObjectSave trigger set on the field that runs this script, then what will happen is this:

           

          Set Variable

          Set Variable

          Set Field

          {script triggers here because the field has been modified}

          Set Variable

          Set Variable

          Set Field

          {script triggers here because the field has been modified}

          etc.

           

          I would change the trigger from OnObjectModify to OnRecordCommit. That way, it only fires once.

           

          HTH

           

          Mike

          • 2. Re: Script runs into indefinite loop when script triggered
            alangodfrey

            Is the script triggered on the field Mails::Mail_Text?

            Is it that it is triggered when you change its value, but again (and again, and again) when it re-sets the value from [kr] to 'kind regards'?

             

            (BTW: 'shortcakes' = 'shortcuts' )

            • 3. Re: Script runs into indefinite loop when script triggered
              Mike_Mitchell

              As an aside, if all you want to do is substitute the full text for the abbreviation (shortcake, shortcut), then you could just do this:

               

              1) Create a table of abbreviations and full text.

              2) Create a relationship between the abbreviation field and the abbreviation in the abbreviation table.

              3) Set an auto-enter calc to insert the full version.

               

              No Script Triggers required.

              • 4. Re: Script runs into indefinite loop when script triggered
                alangodfrey

                Depending on what the actual text field is that you are building it might be good to have a separate drop down to select the phrase to insert, then click a button to add it to the text field you are building.

                We use that technique to let users build reports quite quickly, with very little typing.

                 

                Eg:

                - Choose 'Hello' from the drop down, click the button, and it enters:

                Hello, Good Morning, and Welcome

                into the text field.

                 

                - Choose 'Sorry Late' from the drop down, click the button, and it adds more text to make the field read:

                'Hello, Good Morning, and Welcome,

                We are sorry to hear that your order was late.'

                 

                - Choose 'Regards' from the drop down, click the button, and it adds more text to make the field read:

                'Hello, Good Morning, and Welcome,

                We are sorry to hear that your order was late.

                Kind regards

                Luna Media'

                 

                 

                (- Choose 'Sorry Late' and click the 'Deutsch' button and it would have added:

                Es tut uns leid zu hören dass Ihre Bestellung spät (or something) )

                 

                ---

                 

                Another technique we use is to type in the text field:

                [hg] Dieter,

                [sl]

                [kr] etc

                 

                and then click the 'Convert' button, which runs a script with the Substitute function and replaces the placeholder text with the 'translation'.  We also use placeholders like [name] and [hisher] and if the file knows who the mail is directed to it will insert:

                'Hello, Dieter

                Sorry to hear that his order was late,

                etc'

                 

                The range of 'Substitutes' we use in that technique is quite limited ([name], [hisher], [their]..., maybe 4 more) that we can hard-code the Substitutions into the script.  We haven't had to make it extensible to a large number of 'translations' yet.

                • 5. Re: Script runs into indefinite loop when script triggered
                  Mike_Mitchell

                  alangodfrey wrote:

                   

                  The range of 'Substitutes' we use in that technique is quite limited ([name], [hisher], [their]..., maybe 4 more) that we can hard-code the Substitutions into the script. We haven't had to make it extensible to a large number of 'translations' yet.

                   

                  Using a table of substitutions would make that easy enough. But yeah, there are lots of good ways to accomplish this that don't rely on triggers.

                  • 6. Re: Script runs into indefinite loop when script triggered

                    Oh, yes, wrong trigger. Thanks! Thought "OnChange" would not get executed at least after the second run as no changes will be made. But OnCommit is definitely the right one.

                     

                     

                     

                     

                    Am 20.08.2016 um 14:37 schrieb Mike_Mitchell <noreply@filemaker.com>:

                     

                    Script runs into indefinite loop when script triggered

                    Antwort von Mike_Mitchell in Discussions - Komplette Diskussion anzeigen

                     

                    Just those three script steps wouldn't cause a loop. I suspect you have a trigger repeatedly firing. Typically, this is caused by the triggering event causing a script to run that also triggers the same event. I suspect your Set Field script step is the culprit. If you have an OnObjectModify or OnObjectSave trigger set on the field that runs this script, then what will happen is this:

                     

                     

                     

                    Set Variable

                     

                    Set Variable

                     

                    Set Field

                     

                    {script triggers here because the field has been modified}

                     

                    Set Variable

                     

                    Set Variable

                     

                    Set Field

                     

                    {script triggers here because the field has been modified}

                     

                    etc.

                     

                     

                     

                    I would change the trigger from OnObjectModify to OnRecordCommit. That way, it only fires once.

                     

                     

                     

                    HTH

                     

                     

                     

                    Mike

                     

                    Sie können auf diese Nachricht antworten, indem Sie diese E-Mail beantworten oder die Nachricht unter FileMaker Community aufrufen

                    Starten Sie eine neue Diskussion in Discussions per E-Mail oder unter FileMaker Community

                    Sie folgen Script runs into indefinite loop when script triggered in diesen Aktivitätenlisten: Posteingang

                    Bearbeiten Sie Ihre Emailvoreinstellungen

                     

                    FileMaker Developer Conference 2016 • Las Vegas, Nevada • July 18-21 • www.filemaker.com/devcon

                     

                    • 7. Re: Script runs into indefinite loop when script triggered

                      Not sure how this can work. My text is longer like

                       

                      Thanks.

                       

                      Martin

                       

                      It will not get changed without running some script I think.

                       

                       

                       

                       

                      Am 20.08.2016 um 14:42 schrieb Mike_Mitchell <noreply@filemaker.com>:

                       

                      Script runs into indefinite loop when script triggered

                      Antwort von Mike_Mitchell in Discussions - Komplette Diskussion anzeigen

                       

                      As an aside, if all you want to do is substitute the full text for the abbreviation (shortcake, shortcut), then you could just do this:

                       

                       

                       

                      1) Create a table of abbreviations and full text.

                       

                      2) Create a relationship between the abbreviation field and the abbreviation in the abbreviation table.

                       

                      3) Set an auto-enter calc to insert the full version.

                       

                       

                       

                      No Script Triggers required.

                       

                      Sie können auf diese Nachricht antworten, indem Sie diese E-Mail beantworten oder die Nachricht unter FileMaker Community aufrufen

                      Starten Sie eine neue Diskussion in Discussions per E-Mail oder unter FileMaker Community

                      Sie folgen Script runs into indefinite loop when script triggered in diesen Aktivitätenlisten: Posteingang

                      Bearbeiten Sie Ihre Emailvoreinstellungen

                       

                      FileMaker Developer Conference 2016 • Las Vegas, Nevada • July 18-21 • www.filemaker.com/devcon

                       

                      • 8. Re: Script runs into indefinite loop when script triggered

                        Good solution. But I do not like to use the mouse much... And sometimes I need a shortcode    in between some text if refining it.

                         

                        Or is there a way to insert text at the "last place of the cursor when I  leaving the field"?

                         

                        Am 20.08.2016 um 15:51 schrieb alangodfrey <noreply@filemaker.com>:

                         

                        Script runs into indefinite loop when script triggered

                        Antwort von alangodfrey in Discussions - Komplette Diskussion anzeigen

                         

                        Depending on what the actual text field is that you are building it might be good to have a separate drop down to select the phrase to insert, then click a button to add it to the text field you are building.

                         

                        We use that technique to let users build reports quite quickly, with very little typing.

                         

                         

                         

                        Eg:

                         

                        - Choose 'Hello' from the drop down, click the button, and it enters:

                         

                        Hello, Good Morning, and Welcome

                         

                        into the text field.

                         

                         

                         

                        - Choose 'Sorry Late' from the drop down, click the button, and it adds more text to make the field read:

                         

                        'Hello, Good Morning, and Welcome,

                         

                        We are sorry to hear that your order was late.'

                         

                         

                         

                        - Choose 'Regards' from the drop down, click the button, and it adds more text to make the field read:

                         

                        'Hello, Good Morning, and Welcome,

                         

                        We are sorry to hear that your order was late.

                         

                        Kind regards

                         

                        Luna Media'

                         

                         

                         

                         

                         

                        (- Choose 'Sorry Late' and click the 'Deutsch' button and it would have added:

                         

                        Es tut uns leid zu hören dass Ihre Bestellung spät (or something) )

                         

                         

                         

                        ---

                         

                         

                         

                        Another technique we use is to type in the text field:

                         

                        Dieter,

                         

                         

                         

                        etc

                         

                         

                         

                        and then click the 'Convert' button, which runs a script with the Substitute function and replaces the placeholder text with the 'translation'.  We also use placeholders like  and  and if the file knows who the mail is directed to it will insert:

                         

                        'Hello, Dieter

                         

                        Sorry to hear that his order was late,

                         

                        etc'

                         

                         

                         

                        The range of 'Substitutes' we use in that technique is quite limited (, , ..., maybe 4 more) that we can hard-code the Substitutions into the script.  We haven't had to make it extensible to a large number of 'translations' yet.

                         

                        Sie können auf diese Nachricht antworten, indem Sie diese E-Mail beantworten oder die Nachricht unter FileMaker Community aufrufen

                        Starten Sie eine neue Diskussion in Discussions per E-Mail oder unter FileMaker Community

                        Sie folgen Script runs into indefinite loop when script triggered in diesen Aktivitätenlisten: Posteingang

                        Bearbeiten Sie Ihre Emailvoreinstellungen

                         

                        FileMaker Developer Conference 2016 • Las Vegas, Nevada • July 18-21 • www.filemaker.com/devcon

                         

                        • 9. Re: Script runs into indefinite loop when script triggered
                          Mike_Mitchell

                          Set Field

                           

                          No reason it can’t work with gigabytes of text.

                          • 10. Re: Script runs into indefinite loop when script triggered
                            Mike_Mitchell

                            Go to Field

                            Insert Calculated Result

                            • 11. Re: Script runs into indefinite loop when script triggered

                              Yes, we do use more on the Mac itself using Word etc, some standard phrases and even longer standard paragraphs.

                               

                              That is more a question of what the use case is.

                               

                              In addition we want to have the appropriate language version at hand if a contact has another language.

                               

                              What I could do is to haave a loop through all items of the shortcode table an do the replacements.

                               

                              Maybe it would be better to find all "[...]" occurrences at first and just look for theses so that at best if not shortcode is used no table lookup has to be performed.

                               

                              But as there seems to be no concept as an "array" (global) variable I am used from PHP that could be stuffed once - I am still looking for an even more elegant way...

                               

                               

                              Am 20.08.2016 um 16:02 schrieb Mike_Mitchell <noreply@filemaker.com>:

                               

                              Script runs into indefinite loop when script triggered

                              Antwort von Mike_Mitchell in Discussions - Komplette Diskussion anzeigen

                              >

                              • 12. Re: Script runs into indefinite loop when script triggered

                                And how does the calculation look like - some advice would be great!

                                 

                                 

                                 

                                 

                                Am 20.08.2016 um 16:14 schrieb Mike_Mitchell <noreply@filemaker.com>:

                                 

                                Script runs into indefinite loop when script triggered

                                Antwort von Mike_Mitchell in Discussions - Komplette Diskussion anzeigen

                                 

                                Go to Field

                                 

                                Insert Calculated Result

                                 

                                Sie können auf diese Nachricht antworten, indem Sie diese E-Mail beantworten oder die Nachricht unter FileMaker Community aufrufen

                                Starten Sie eine neue Diskussion in Discussions per E-Mail oder unter FileMaker Community

                                Sie folgen Script runs into indefinite loop when script triggered in diesen Aktivitätenlisten: Posteingang

                                Bearbeiten Sie Ihre Emailvoreinstellungen

                                 

                                FileMaker Developer Conference 2016 • Las Vegas, Nevada • July 18-21 • www.filemaker.com/devcon

                                 

                                • 13. Re: Script runs into indefinite loop when script triggered
                                  alangodfrey

                                  "Using a table of substitutions would make that easy enough" - Any chance of a wee pointer in the right direction, Mike...?

                                   

                                  The modular, unconverted, place-holdered text might read:

                                  "[name] was in good form today as [heshe] had a visit from [their] friends."

                                   

                                  Because we know the person is male, on button-click (or other trigger) the script substitutes the placeholders so it reads:

                                  "Mike was in good form today as he had a visit from his friends."

                                   

                                  It would be great to have a technique that allowed us to simply add more records in a table when we want to add more placeholders for substitution, rather than adjust the hard-coded script.

                                   

                                  Obviously we have an existing table to convert (100+) short-codes into long-codes for the initial text creation, such as:

                                  Short code                  Text to insert

                                  Good Form Friends     [name] was in good form today as [heshe] had a visit from [their] friends.

                                   

                                  (Sorry for hijacking your Post, Luna Media, but hopefully Mike's ideas on this will be helpful to you, too.)

                                  • 14. Re: Script runs into indefinite loop when script triggered
                                    alangodfrey

                                    Ah....  Create a loop script to run down the list of PlaceHolders and substitute...?

                                     

                                    Food for thought - thanks for stirring me into action, Mike.

                                     

                                    EDIT: Nope: lightbulb moment just went out.

                                    1 2 Previous Next