AnsweredAssumed Answered

Stock Ledger script crashes FMPa - but not in debugger!

Question asked by philmcgeehan on Nov 18, 2013
Latest reply on Nov 18, 2013 by davidanders


Stock Ledger script crashes FMPa - but not in debugger!


     When I step through my script in the debugger, FileMaker has no problem and carries out the instructions as expected; however, when I try to run the script my pressing a button, it crashes FMPa with a generic Windows dialog box message.angry

     What I'd expect to happen is the user type in a quantity (temp_Qty) next to the stock item they wish to Book Out.
     Click the Book Out button and the following script should run.
     First it should check to see if the user has entered a quantity, otherwise the 401 error custom dialog pops up and exits the script.
     If there is a quantity it'll get the item info and create a new record in the Stock Ledger with the quantity to book out.
     When It finishes the loop it should display a new window in preview mode, for the user to print a report on what stock has just been booked out.

Set Variable [ $HasPrinted ; Value:0 ]
Set Variable [ $Counter; Value:0 ]

    Set Variable [ $Counter ; Value:$Counter + 1 ]
    #Go to products list and find records that have temp_Qty values
    Go to Layout [ “ProductsImport” (ProductsImport) ]
    Set Error Capture [ On ]
    Perform Find [ Find Records ; Criteria: ProductsImport::Temp_Qty : “*” ][ Restore ]
    If [ Get ( LastError ) = 401 ]
        Show Custom Dialog [ Message: "There are no items with a Book Out qty"]
        Close Window [ Current Window ]
        #Will exit the script if no items with a book out qty are found
        Set Error Capture [ Off ]
        Exit Script [ ]
    End If
    Set Error Capture [ Off ]
    If [ $Counter = 1 ]
        #If it's the first time in the loop, then get a Record Count
        Go to Record/Request/Page [ Last ]
        Set Variable [ $RecCount ; Value:Get ( RecordNumber ) ]
        Go to Record/Request/Page [ First ]
        #Go to the Record that matches the counter
        Go to Record/Request/Page [ $Counter ]
    End If

    #Get the Product Info and Quantity to Book Out on the Stock Ledger
    Set Variable [ $Prod; Value:ProductsImport::_kp_ProductID ]
    Set Variable [ $Qty ; Value:ProductsImport::Temp_Qty ]
    Go to Layout [ “StockLedger Admin” (StockLedger) ]
    New Record/Request
    Set Field [ StockLedger::_kf_Location ; System::temploc ]
    Set Field [ StockLedger::_kf_ProductID ; $Prod ]
    Set Field [ StockLedger::QtyOUT ; $Qty ]
    Set Field [ StockLedger::Type ; "Consumed" ]
    Commit Records/Requests
    Exit Loop If [ $Counter = $RecCount ]
End Loop

    Go to Related Record [ From table: “Products|StockItems” ; Using layout: “StockBookOut_PrintReport” (Products|StockItems) ] [ New window ]
    Perform Find [ Specified Find Requests: Find Records ; Criteria: ProductsImport::Temp_Qty : “*” ] [ Restore ]
    Print Setup [ Orientation: Portrait ; Paper size: 8.26" x 11.69" ] [ Restore; No dialog ]
    Show/Hide Toolbars[ Hide ]
    Enter Preview Mode
    Adjust Window [ Resize to Fit ]


     Sometimes it looks as though it gets to the new report window, but then crashes.

     But it seems it won't even get to the 401 error message at the beginning if I don't enter any quantities.


     Does it crash for anyone else?

     Is there something obviously wrong?