5 Replies Latest reply on Feb 26, 2014 1:01 PM by philmodjunk

    Deleting Records Bug (in my script)

    brodlang

      Title

      Deleting Records Bug (in my script)

      Post

           I have 2 similar but different scripts that work on different tables that are giving me a similar problem. I'm sure I'm missing something in my novice programming.  Occassionally, the script will delete records that it shouldn't.  I haven't been able to determine what factors are in place when this happens so I can't just duplicate to try and debug. One example is listed below.  The tables involved are Heading 4, Copy Preps and Door Preps.  The layout is based on Heading 4.  Door Preps is a portal on the layout. Data is entered into Door Preps for each record in Heading 4.  The purpose of the script is to copy the Door Preps data from one Heading 4 record (variable) to the current Heading 4 record. Works like a charm 95% of the time, but the other 5% it deletes all the current record set in Heading 4, which is strange because almost all the action happens in the other two tables.  Any ideas what I'm missing here?  (Sorry for the sloppy upload)

            

            

      Doors2_-_2_%28LANG-FM%29.jpg

        • 1. Re: Deleting Records Bug (in my script)
          philmodjunk

               Well we can't see what criteria you are using in your find steps so we can't see how that might fail. It for DoorPreps, it looks like you might get this result if the Find fails to find any records matching the stored criteria.

               And for CopyPreps, your script simply changes layouts. DeleteAll Records will delete whatever records happen to be in the current found set, there doesn't appear to be anything in your script to control what records are in that found set before the delete step deletes them.

               I suggest that for DoorPreps, you add some code that compares Get ( FoundCount ) to Get ( TotalRecords) before deleting all records. If the results of those two functions are equal, your script is about to delete all records from the table. Thus, you can set up an IF step that checks for this and that then halts the script so that you can inspect the records shown to see if you can figure out why your Find failed to find records.

          • 2. Re: Deleting Records Bug (in my script)
            brodlang

                 Hi Phil,

                 The Copy Preps is a table that hold the records temporarily until they can be imported later in the script.  So my first step is to go to that layout and delete all the records.  That way the records I import there will be the only ones in that table. Once the script is done I don't need that data anymore. 

                 The first find is for Door Preps. It finds all records related to the current record in Heading 4 and Deletes All those records making way for the new records I want to import. 

                 Next I Find the Door Prep records I want to copy ($From) from and import them into Copy Preps. 

                 Then I run a loop on those records (in Copy Preps) to set the Heading field to match the original related record.

                 Thin I import them back into Door Preps. 

                 Like I said, it usually works slick.  But when It doesn't, records are deleted in Heading 4!!  Why there?  And why so infrequently? As far as I can tell, Heading 4 layout shouldn't even be the active window during the Delete commands.

            • 3. Re: Deleting Records Bug (in my script)
              philmodjunk
                   

                        So my first step is to go to that layout and delete all the records.

                   But it may not delete all the records. I recommend a show all records step  to be sure.

                   

                        The first find is for Door Preps. It finds all records related to the current record in Heading 4...

                   Yes but exactly HOW does it do that? What citeria are you using?

                   

                        ... and Deletes All those records making way for the new records I want to import.

                   Yes, but for some reason you are either getting invalid search criteria on occasion or your find criteria is finding all records. I have suggested a way to detect this condition and halt the script so that you can investigate further. I suggest that you use a show custom dialog step that displays the values of any variables used with your stored find criteria when this situation is detected.

              • 4. Re: Deleting Records Bug (in my script)
                brodlang

                     Thanks, Phil.  I have added the "Show All Records" step you suggested.

                     The find criteria is  DoorPreps::ProjectNo [==$$Proj} AND DoorPreps::Heading: [$To]

                     I can (and will) add the steps for Door Preps that will check the record count against the found count, but these are not the records I'm accidently deleting. The records are being deleted from the original layout Heading 4 table - not all of them, but the current found set. Is it possible that one of the Go To Layout steps is somehow being missed or corrupted so that the subsequent Delete All Records is happening on my original layout? 

                • 5. Re: Deleting Records Bug (in my script)
                  philmodjunk

                       Or could it be that something other than just this script is deleting your records?

                       What you describe is typical of a script that uses Go to Related records step to bring up the records and delete them. If there are no related records and you don't check for that possibility in your script, the script fails to change layouts and the record deleting happens on the wrong table/layout.

                       But you don't use that script step here.

                       Another possibility is that you have a "delete" option specified in one of your relationships that you shouldn't have. With that option specified, deleting records in table A can delete records in Table B if they are related to the records so deleted. That also seems unlikely or I'd expect to see more records going missing on you every time you run the script, but maybe there's an additional detail that only sometimes leaves such relationship in place and thus only sometimes records disappear from Header.