5 Replies Latest reply on Sep 27, 2012 7:12 AM by philmodjunk

    Delete Records

    bablahemen

      Title

      Delete Records

      Post

           Hello All,

            

           I have posted this script. i am facing problem with delete the records base on the condition in this script. please let me know where is my error.

            

           i have attached the script screenshot and also the database relationship.

            

           Regards

           Hemen.

      Screen_Shot_2012-09-26_at_13.05.56.png

        • 1. Re: Delete Records
          bablahemen

               The Second Image...

          • 2. Re: Delete Records
            shilpas@metasyssoftware.com

                 Hi,

                 Script specifies that you want to delete the matching records - having same values of OrderNo, ProductCode and Qty in both tables,  from OnOrder table. In order to achieve this, change the relationship - set the relationship on basis of three fields - OrderNo, Itemcode (ProductNo) and itemQty (ProductQty) of two tables (SRVOrder and ONOrder).

                 here is pseudo code of script

                 Go To Layout SRV Order
                 Show All
                 Go to first record
                 Loop
                 If Count(OnORDER::Order_No)>0
                     GTRR
                     Delete all records
                     Go To layout SRV ORDER
                 End If
                 Go To Record Request Page [Next,exit after last]
                 End Loop

            • 3. Re: Delete Records
              philmodjunk

                   Your script has a number of problems.

                   Your Go TO Related Records step will leave you on the wrong layout if there are no related records and then your delete records might delete them from the wrong table. You should always check for the existance of related records just before the GTRR step or for an error code immediately after the GTRR step to properly handle situations where there are no related records.

                   Get (lasterror) as written, will never return an error. Get (LastError) must be used immediately after the step that might generate the error for which you are testing. As written, Get (LastError) would return an error only if the IF step immediately above it generated an error.

                   It's not clear to me exactly what you are trying to do. Do you want to delete records from SRV Order or OnOrder? I'd guess you want to delete from OnOrder.

                   What is the purpose of these two tables? It's a bit unusual to have so many fields in both tables with exactly the same information. Usually, it's better to put that data in only one table and use the relationship to refer to it from the other, but this also requires a proper primary key to foreign key relationship to make that work.

              • 4. Re: Delete Records
                bablahemen

                     Hi, Thks for the response.

                     My point is to delete the record on ONOrder table, when its match with the 3 related condition, else has to reduce the Qty in OnOrder Qty.

                     Like

                     If SrvOrNo = OrderNo

                          IF SRVItem = Onorder

                               If Srv Itemqty = Onorder Qty

                                      Delete record in Onorder Table,

                               Else

                                  OnorderQty = Onorderqty-SrvQty

                      

                     I want to have this kind of script.

                      

                      

                • 5. Re: Delete Records
                  philmodjunk

                       The problem is that you may have many records in OnOrder that match to the Current record in Srv Order and your If steps only refer to the first such related record. Your comparisons need to be made from the context of OnOrder, not Srv Order.

                       If [Not IsEmpty ( ONOrder::Order_No) ]
                           Go To Related Records
                           //Then check the other two values now that you are "on" the OnOrder table instead of Srv Order