February 24, 200916 yr I have done many scripts with loops but today I am having a brain freeze I believe. I am working on a payment screen for our database. There is a field for check amount and amount remaining. Then a portal which lists outstanding invoices for a specific customer. I want to click an 'Auto Apply" button that loops through the portal rows and applies the payments, Apply the full amount of the balance if the amount remaining is > or = the balance or apply the amount remaining if the balance is > than the amount remaining. For some reason it's not working correctly. The last portal row does not apply correctly. Here's the script, I'm sure it's something stupid that I'm missing. Set Error Capture [ On ] If [ Payments::Outofbalance ≤ 0 ] Show Custom Dialog [ Message: "No payments to apply."; Buttons: “OK” ] Halt Script End If Go to Portal Row [ Select; First ] Loop Exit Loop If [ Payments::Outofbalance = 0 ] Go to Portal Row [ Select; Next; Exit after last ] If [ Payments Inv Client::Balance ≤ Payments::Outofbalance ] Set Field [ Payments Inv Client::Amounttoapply; Payments Inv Client::Balance ] Else If [ Payments Inv Client::Balance > Payments::Outofbalance ] Set Field [ Payments Inv Client::Amounttoapply; Payments::Outofbalance ] End If End If End Loop Edited February 24, 200916 yr by Guest
March 2, 200916 yr would it work if you freeze the window, then script a GTRR (show only related records), do your loop there, and return to the last layout?
March 6, 200916 yr The most obvious thing - which I think is in error - is that you have the "Go To Portal Row: Select: Next: Exit after last" in the loop *before* any processing steps. Unless you intend to skip the 1st portal row, the "go to next" step ought to be immediately before the "End Loop" step. The other things that "appear" to be in error is the absence of any step which adjusts the amounts remaining after applying a payment. If I'm right about this, then your script would apply the lessor of the client's check amount or the invoice balance, to every row in the portal except the 1st. Since you are ranked "Advanced", I doubt that I have debugged your problem, but you never know. Chappy
Create an account or sign in to comment