7 Replies Latest reply on Dec 3, 2013 8:58 AM by willrollo

    Script issue with loop

      Title

      Script issue with loop

      Post

      Following on from prev post earlier, I have adapted a script to my database that is designed to update the physical stock amounts of a list of invoiced items. The problem I am having is that the script appears to add up the total quantities of each item, and then takes that figure from the first line item in the inventory as opposed to taking each individual line item quantity from the stock quantity for that product...Help hugely appreciated...!
             
      •            
      •      
      •           Allow User Abort [ Off ]
      •      
      •           Set Error Capture [ On ]
      •      
      •           Commit Records/Requests [ No dialog ]
      •      
      •           Freeze Window
      •      
      •           If [ Get ( ScriptParameter ) = "commit" and INVOICE DETAILS::flag_items_committed ≠ 1 ]
      •      
      •           Set Field [ INVOICE DETAILS::flag_items_committed; 1 ]
      •      
      •           Else If [ Get ( ScriptParameter ) = "commit" and INVOICE DETAILS::flag_items_committed = 1 ]
      •      
      •           Exit Script [ ]
      •      
      •           Else If [ Get ( ScriptParameter ) = "uncommit" and INVOICE DETAILS::flag_items_committed = 1 ]
      •      
      •           Set Field [ INVOICE DETAILS::flag_items_committed; "" ]
      •      
      •           Else If [ Get ( ScriptParameter ) = "uncommit" and INVOICE DETAILS::flag_items_committed ≠ 1 ]
      •      
      •           Exit Script [ ]
      •      
      •           End If
      •      
      •           Set Variable [ $id_invoice; Value:INVOICE DETAILS::ID_Invoice_pk ]
      •      
      •           Loop
      •      
      •           Set Variable [ $row; Value:$row + 1 ]
      •      
      •           Go to Portal Row [ $row ] [ Select; No dialog ]
      •      
      •           Exit Loop If [ Get ( LastError ) = 101 ]
      •      
      •           Set Variable [ $quantity; Value:invoicedetails_INVOICEITEM::Quantity ]
      •      
      •           Go to Related Record [ From table: “invoicedetails_InvoiceItem_PRODUCTS”; Using layout: “FL Product Detail” (PRODUCTS) ]
      •      
      •           Set Variable [ $old_stock; Value:PRODUCTS::FL Stock Remaining ]
      •      
      •           Set Variable [ $id_product; Value:PRODUCTS::ID_Item_pk ]
      •      
      •           If [ Get ( ScriptParameter ) = "commit" ]
      •      
      •           Set Field [ PRODUCTS::FL Stock Remaining; PRODUCTS::FL Stock Remaining - $quantity ]
      •      
      •           Else If [ Get (ScriptParameter) = "uncommit" ]
      •      
      •           Set Field [ PRODUCTS::FL Stock Remaining; PRODUCTS::FL Stock Remaining + $quantity ]
      •      
      •           End If
      •      
      •           If [ PRODUCTS::FL Stock Remaining < 0 ]
      •      
      •           Set Variable [ $error; Value:$error & PRODUCTS::Description & ": " & PRODUCTS::FL Stock Remaining & ¶ ]
      •      
      •           End If
      •      
      •           Go to Layout [ original layout ]
      •      
      •           End Loop
      •      
      •           Commit Records/Requests [ No dialog ]
      •      
      •           If [ $error ≠ "" ]
      •      
      •           Show Custom Dialog [ Title: "Warning"; Message: "The following items are out of stock. Here are the stock amounts for each that is out." & ¶ & ¶ & $error; Default Button: “OK”, Commit: “Yes” ]
      •      
      •           End If