1 2 Previous Next 15 Replies Latest reply on Aug 8, 2012 9:31 AM by mcward9884

    Create new records in seperate table by found count?

    JessOttman_2

      Title

      Create new records in seperate table by found count?

      Post

       Hi,

      I have two tables in this particular database. in the first table i have records of products.If i do a find using the po number lets say i get 4 records. I would like to create the number of found records in another table afte clicking a button.

      I have created a script but i have gone wrong and just need the best wat to do this. here is my attempted script

      If i trigger the script the first time its fine if i do it again for the same found count its doesnt stop creating records in the other table...

       

      untitled.JPG

        • 1. Re: Create new records in seperate table by found count?
          mcward9884

          I believe that the problem with your loop is that on the second running of your script, you already have more records in the new table than the "get (foundcount)" number in the "gcreate new" field.  Thus causing the loop to continue.  Try adding a "counter" step to the script.  You can set a variable to keep track.

          After the New Record/Request step, add a script step to Set Variable [$Variable; Value:1]

          Then, inside the loop, set the variable to update, Set Variable [$Variable; Value:$Variable +1]

          And then change the Exit Loop If to be Exit Loop If [Get (FoundCount) = $Variable]

          Hopefully, this should fix your looping problem.

          • 2. Re: Create new records in seperate table by found count?
            JessOttman_2

             Hi Colleen

            I have followed your instuructions for fixing the looping problem in my script however it still seems to create non stop.

             I wonder have i approached this wrong and there is more than likely a much beter way to do it.

            Thank you very much for your reply il keep trying your sugestion as its more than likely my error causing it not to work

            Jess

             

            • 3. Re: Create new records in seperate table by found count?
              mcward9884

              Sorry, that is totally my fault.

              The Exit Loop If should say Exit Loop If [TEST REPORT TABLE::gcreate new = $Variable].

              Also, I am assuming that the gcreate new field is a global field since you started it with "g".

              Let me know if that fixes it.

              • 4. Re: Create new records in seperate table by found count?
                JessOttman_2

                 No prblem 

                Unfortunately it is still creating multiple records after its required found count number. So it doesnt look like that was it either.

                Also yes, the gcreate new field is indeed a global.

                 

                • 5. Re: Create new records in seperate table by found count?
                  mcward9884

                  Hmmm.  Can you re-send a screen shot of the script?

                  • 6. Re: Create new records in seperate table by found count?
                    JessOttman_2

                     Here is another screen shot in which i think ive done what you said(hopefully)

                     

                    • 7. Re: Create new records in seperate table by found count?
                      Sorbsbuster

                      Does the 3rd step (Omit Multiple) not mean that you'll simply have a found set of zero records?

                      You also have a typo in the $Variable name, so the Exit loop if step will not work.

                      • 8. Re: Create new records in seperate table by found count?
                        JessOttman_2

                        Thank you for your observation of the typo I have corrected the mistake now.

                        As for the Omit records step it doesnt seem to be a problem due to when i use script debugger no error shows,but ive taken it out nonetheless.

                        I have altered some of my script so now it works perfectly the firdt time. However when i try to run the script for another set of records it doesnt exit the loop.

                        Im at a bit of a loss...

                        • 9. Re: Create new records in seperate table by found count?
                          philmodjunk

                          You are back to the original problem, if there is a found Set on "Test Reports" that is greater than or equal to the found set of whatever layout is current when you perform this script your loop will never exit.

                          Loop
                             Set Variable [$K ; Value: $K + 1 ]
                             Exit loop if [$K > Test Report Table::gtest report]
                             New Record/Request
                          End Loop

                          PS. IF you have the FileMaker Advanced and a script isn't working, enable the debgger and data viewer, then perform your script and use the debugger controls to step through your script one step at a time--watching values in fields and variables change and watching what happens on the layout. This will often show you exactly where and why your script goes wrong. You can even set up "watch" calculations such as Get (FoundCount) so you can see how if and exit if calculations are evaluating.

                          • 10. Re: Create new records in seperate table by found count?
                            JessOttman_2

                             Hi Phil

                            Thank you for your help i did as you said and it seems to work well.

                            Ive edited my script again however I am unsure if there are still flaws that could create an error during the running of the script.

                            • 11. Re: Create new records in seperate table by found count?
                              mcward9884

                              I don't think you need the step to Set Field [TEST REPORT TABLE::gtest report; Get (FoundCount)], as you have already placed the "found count" in a global field "TEST REPORT TABLE::gcreate new".

                              You also don't seem to need the step to Omit Multiple Records

                              Then the Exit Loop If step should read Exit Loop If [TEST REPORT TABLE::greate new = $Variable], not if it = Get (FoundCount)].

                              The variable is the counter and it is counting how many records you have created, so that you create the number of records you found earlier in the script.

                              You are also missing the step to set the variable initially as 1.

                              The script should read:

                              Insert Calculated Result [Select; TEST REPORT TABLE::gcreate new; Get (FoundCount)]

                              Go to Layout ["TEST REPORTS" (TEST REPORT TABLE)]

                              Set Variable [$K; Value:1]

                              New Record/Request

                              Loop

                                 Exit Loop If [TEST REPORT TABLE::gcreate new = $K]

                                 Set Variable [$K; Value:$K +1]

                                 New Record/Request

                              End Loop

                               

                              • 12. Re: Create new records in seperate table by found count?
                                philmodjunk

                                @colleen,

                                 I used to put a set variable to initiate counter variables as 1 all the time. (standard good programming practice), but then I found that in FileMaker, I could leave the step out and the Set Variable [$K ; value: $K + 1] will correctly assign 1 to the variable the first time around so the step isn't needed. Either way works as long as you increment the counter in the correct point in the loop (The location changes if you set it to 1 outside the loop).

                                • 13. Re: Create new records in seperate table by found count?
                                  mcward9884

                                  Hi Phil,

                                  Thanks for the tip.  I did not kow that about the initial step, and I love learning new things about FileMaker!

                                  Can I ask a totally separate question?  I put a question on the forum for myself, but have not had any responses.  Has anyone else had any trouble with the paragraph symbol in the send mail script with the new version 12.  I have Mac 10.6.8 and use Entourage.  Everything was working fine in Version 11, but now messages in the body of an e-mail do not recogize a carriage return and everything runs together.

                                  Thanks.

                                  • 14. Re: Create new records in seperate table by found count?
                                    philmodjunk

                                    I know of no trouble reports and that's not a combination of Operating system, and email client that I have any experience with. I have seen posts of cases where this happened in Outlook and while I don't recall the exact details, there was a setting in Outlook that had to be specified. I have no idea if the same might be true for Entourage. (note, you can always use Post A Answer to reply to your own question to "bump" it back to the top of Recent Items.

                                    1 2 Previous Next