1 Reply Latest reply on Mar 19, 2015 1:45 AM by raybaudi

    Where is the bug in my script?

    brodlang

      Title

      Where is the bug in my script?

      Post

      FYI - I'm no power user, but I can usually figure things out.  My apologies if my posting location or etiquette here are wrong.

      I have a problem that has plagued me for a couple of years. It may only occur 5% (about 5 times a month) of the time this script runs.  The short story is that it will delete all the current records of the main table of the layout, even though that table is not even referenced in the script, except to set some variables and in an IF statement that will halt the script if one of the variables is blank.  I've made a safety to save the data first, but it's not the best workaround.  

      I have a layout called "HardwareHeadings" that is based on the table "Headings".  The script below is a utility that will copy all the matching records in a related portal (HeadingHardware) from one Heading record to another.  However, occasionally, all my "Heading" records get deleted.

      I'm not sure, but the delete appears to happen immediately, before the script fully executes.

      Also, if you have way I can disallow a "delete all records" on a layout page, I'd love to hear that, too.

      Thanks for your help.

      Script follows:

      Set Error Capture [On]

      Set Variable [$RN Value:Get (RecordNumber )]

      //Perform Script [HeadingsSavedHH]

      If [Heading: :HeadingCopyHMF > 1] *** Until today this read: If [HeadingCopyHMF  ≠ "" ]

      Set Error Capture [On]

      Set Variable [$From; Value:Heading: :HeadingCopyHMF]

      Set Variable [$To; Value:Heading: :Heading]

      Go to Layout [HeadingCopyTemp" (HeadingCopyTemp)]

      Delete All Records No dialog]

      Go to Layout [HeadingHardware" (HeadingHardware)]

      Perform Find [Restore]

      Delete All Records [No dialog]

      Perform Find [Restore]

      Import Records [No dialog; "Doors.fmp 12"; Add; Windows ANSI]

      Go to Layout [HeadingCopyTemp" (HeadingCopyTemp)]

      Go to Record/Request/Page [First]

      Loop

      Set Field [HeadingCopyTemp: :Heading; $To]

      Go to Record/Request/Page [Next; Exit after last]

      End Loop

      Import Records No dialog; "Doors.fmp 12"; Add; Windows ANSI]

      Go to Layout [original layout]

      Sort Records [Restore; No dialog]

      Go to Record/Request/Page No dialog; $RN]

      End If

      Set Error Capture [Off]