9 Replies Latest reply on Mar 14, 2013 9:42 AM by weedonpaul

    I want to Search for a record and if not there Create

    weedonpaul

      Title

      I want to Search for a record and if not there Create

      Post

           Does any one have a script that Looks at a table to find a record and if thge record isn't there it creates on.

           I'm trying to Look for a record for a given month and year and if there isn't one it creates one. However I dont want someone (Me) missspelling a month and creating a record when it didn't need to

           I used custom messages to get month and year inputs from user and that worked except when I missspelled March it created a new recored for Mrch.

           I then tried creating a layout that would behave as a custom dialouge box but it didn't unless i pepper the script with pauses

           Now I have a head ache

           Paul

        • 1. Re: I want to Search for a record and if not there Create
          philmodjunk

               What version of FileMaker are you using. If you are using FileMaker 12, there are options you can use with the New Window command that make the new window "modal" (Behave like a dialog box). If you have an older version then a single pause inside an infinite loop can be used to keep a window in the front until dismissed.

               Either way, a value list can be used to avoid data entry mistakes with a month name.

               If you went back to your original script, there are ways to check the value entered for the month name to be sure that a correct value was entered that can keep an error in the month name from creating a record that shouldn't be created. You can even set up a calculation that takes the first 3 letters of the month name and uses only that info in searching out an determining whether a new record need be created.

          • 2. Re: I want to Search for a record and if not there Create
            weedonpaul

                 I'm using FM11 

                 bellow is the script i created to continue after month and year are entered. the top bit is to avoid blanks I have a beep for now but I was wondering if I could have a loop here? the end if should be before the close window I changed it by accident when creating picture.

                 The variables aren't created and I don't know why

                  

            • 3. Re: I want to Search for a record and if not there Create
              weedonpaul

                   this is the scrip that calles searches for the records

              • 4. Re: I want to Search for a record and if not there Create
                philmodjunk

                     Whether any variable is created will depend on the table occurrence context of the active window. If the layout of the current window is based on Invoice and there are values in the month and year fields, the variables should be created. I'd guess that you aren't on the correct layout at the time these steps execute.

                     For examples of scripts that open a window to use it as a modal dialog, you might examine the scripts inside the .fp7 copy of the Known Bugs List database.

                • 5. Re: I want to Search for a record and if not there Create
                  weedonpaul

                       So i should go to the layout "invoices" while I preform the steps? I'll try that now

                        

                  • 6. Re: I want to Search for a record and if not there Create
                    weedonpaul

                         It's still not creating the variables. I have FM11 Pr advanced so i can watch the variables

                    • 7. Re: I want to Search for a record and if not there Create
                      weedonpaul

                           is it possible to creat global variables without using any scrip. For example a box on a layout that is not tied to any table and just recieves a variable.

                            

                      • 8. Re: I want to Search for a record and if not there Create
                        philmodjunk
                                            

                                                 It's still not creating the variables. I have FM11 Pr advanced so i can watch the variables

                                            

                                                  

                                       

                                            Then I suggest that you check out what mode, window, layout and record is current at the time these steps execute. Check to see what values, if any appear in the fields referenced by the set variable steps.

                                            Our posts are passing by each other due to simultaneous posting. I just saw the second script. It has several odd features such as a Perform FInd script that has no criteria specified that makes no sense to me. I suggest downloading the file I recommended and looking at the scripts used with the "new" and "edit" buttons on the initial layout of this file for examples of how you can open a new window to use as a modal dialog for data entry.

                             

                                  is it possible to creat global variables without using any scrip. For example a box on a layout that is not tied to any table and just recieves a variable.

                             I don't see how that will help you here. A conditional format expression can create a global variable and assign it a value, but not as a way for the user to input data. You can, however, use fields with global storage in the window you are opening and this is what you should be doing here. A script can then use the data in the global fields to perform a find and, if necessary, create a new record that contains the data in the global fields.

                             For examples of scripted finds that use global variables: Fields: Scripted Find Examples

                        • 9. Re: I want to Search for a record and if not there Create
                          weedonpaul

                               Thank you for all your help. it is now working.