1 2 Previous Next 19 Replies Latest reply on Sep 8, 2015 4:32 PM by schamblee

    Looping Script

    talkersw

      I have a request table with a request ID (serial #). This script is triggered on record commit in layout setup. In another table, a record is being created with the same ID. The information is used from the first table. It's like a request/task system. For some reason, the serial number takes off after running the script and the ID's get created in a loop. From 0-5000 Ids in a matter of a minute. Why is this looping?

       

      Script_Workspace__Cleanv18_copy_.png

        • 1. Re: Looping Script
          schamblee

          You did not provide enough information.  What script trigger are you using and what is the relationship  between the two tables.  Guessing, I would guess that your script trigger is being tripped repeatedly.  

          • 2. Re: Looping Script
            BruceRobertson

            That script cannot loop - as you have written it here.

            If you want help, you need to supply enough information, like posting the entire script, and provide a lot more detailed description.

            • 3. Re: Looping Script
              talkersw

              Sorry for not being more detailed. It is being tripped repeatedly; I think the trigger may be the issue.

               

              Here is my relationship. They are both using the same table, although the req. id in the request table is not the same field as in the admin task table; however, through my script it creates a new record and sets it to that ID value. The rest of the fields are coming from the request table into the task table. It just mirrors the same data.

               

              Manage_Database_for_“Cleanv18_copy”.png

               

              Layout_Setup_and_Cleanv18_copy_and_FMstuff.png

              • 4. Re: Looping Script
                electon

                I think because you don't go to the admin layout where I think a new record needs to be created.

                Because you're ( creating a new record / or modifying fields ) in a related table via the relationship. the script trigger fires the OnCommit again for the second step.

                 

                The Record Open state applies to the main TO even if related records are modified.

                This way you end up in a loop.

                • 5. Re: Looping Script
                  electon

                  The way it's written it will loop till end of times.

                  Especially with "Save record changes automatically" enabled.

                   

                   

                  talkersw

                  On Commit it commits the current one but a new record is created immediately after that and then that one commits triggering again.

                  My remark about related records might apply when not in an OnCommit script.

                  The script fires before the record is actually committed so any changes to related data will be committed in same process.

                  It's the NewRecord step that causes the looping.

                  • 6. Re: Looping Script
                    talkersw

                    pplease see update

                    • 7. Re: Looping Script
                      bigtom

                      electon wrote:

                       

                      I think because you don't go to the admin layout where I think a new record needs to be created.

                      Because you're ( creating a new record / or modifying fields ) in a related table via the relationship. the script trigger fires the OnCommit again for the second step.

                       

                      The Record Open state applies to the main TO even if related records are modified.

                      This way you end up in a loop.

                      electon has your correct answer. Basically you have a script that when triggers when the new records created by the script are committed. Not really a loop. More of a runaway script.

                      • 8. Re: Looping Script
                        Markus Schneider

                        Yes.. You start it by adding/changing a record and clicking outside a field (btw. Why a layout trigger?) and the script will create a new record in the same table. As soon as You click outside of a field (among other methods to commit), another record will be created etc.

                         

                        I don't know how Your first posting looks like since You seem to have updated that, but if You want to have one record created in another TO:

                        - field trigger

                        - script will be fired when one get's out of that field (or commit the record elseway), goes to the OTHER TO, creates a new record there, fills a field - and goes back to the original TO (layout..)

                         

                        If there is a change possible if that field afterwards, make sure that the already existing record in the 'other table' is updated - and not a new one is created (as long a You don't want to have extra records for some reason)

                        • 9. Re: Looping Script

                          This is where using FM Pro Advanced's debugger will show exactly what is happening.

                           

                          Kurt

                          • 10. Re: Looping Script
                            carlosilvia0

                            hi,

                            in fact the loop exists because the script is activated when you save (commit) the record. The script creates a new record and when setting the field "AdminTask::Req.ID" the new commit is activated...the script create a new record..loop!

                            I have ri-created the database and the loop is "terrible".

                             

                            Solution:

                             

                            1) remove in the relationship - Table "AdminTask" - "Allow creating of record in this table via this relationship";

                            1.png

                            2) REMOVE script triggers "On Record Commit" in the layout;

                            3) modify the script "Task Record Create" on:

                            2.png

                            4) create a button "New record" with "Perform Script"->

                            "Task Record Create"

                            • 11. Re: Looping Script
                              talkersw

                              Thanks. This is great; however, there is a loophole. If the requestor uses the native "New Record" and does not click the button with the trigger, then the record never shows up for the user completing the task. Is there a way to prevent a new record unless using the button trigger carrying this script? This seems to be my issue. I do not want the "New Record" option used, that is, unless you can help me to trigger the script from that.

                              • 12. Re: Looping Script
                                talkersw

                                I also notice if requestor triggers the script twice, it creates a duplicate req id in the task creators screen

                                • 13. Re: Looping Script
                                  schamblee

                                  Hide the toolbar and the script so it will only run from the button that you place on the layout.  You could also use a script parameter such as button=true in the button setup, then when the button is press the script will run else have the script to exit if the script parameter is not true.

                                  • 14. Re: Looping Script
                                    talkersw

                                    Thanks a lot!

                                    1 2 Previous Next