Hi,
I have a few forms that have been designed with the autofill script mentioned in this post.
It worked great until I upgraded to Forms 9.2. I had a look at this article: https://support.laserfiche.com/KB/1013538 to see how I can fix the problem, however, I'm not sure I'm implementing this fix correctly.
I'm not sure if my forms were always doing this, but it seems that my function I'm calling on my table change event is looping infinitely.
Could really use some guidance on how to implement the KB fix.
The form itself is used to pass credit on a stock item that was ordered. To pull the details of the stock item, the Sales Order Number must be entered for a lookup to take place. Then a 2nd lookup takes place when the user selects the specific Stock Code value in the table. This 2nd lookup populates the row with stock description, qty and price. These values are used to perform the subtotal calculation. What I find now is the following:
1. Autofill doesn't seem to work automatically when the stock code field is populated
2. If I then manually click on the Autofill button itself and there seems to be an infinite loop of the (sumtotalcredit) function afterwards.
Here is my code:
$(document).ready(function () { //Automatically trigger autofill button // $('.lookupCondition input').lookup(autofill); $('.tblstock').change(tableAutofill); function tableAutofill() { $('.tblstock tbody tr').each(function () { $(this).find('button.autofill').trigger('click'); }); } function autofill() { $('.autofill').trigger('click'); } //trigger for updating stock table values $('.tblstock').on('change', sumtotalcredit); function sumtotalcredit() { var totalcredit = 0; var totalVAT = 0; var subtotalcredit = 0; $('.tblstock tbody tr').each(function () { alert('SumTotalcredit'); var uom = $(this).find('.uom input').val() * 1; var subtotal = 0; var listPrice = $(this).find('.listPrice input').val() * 1; var qtyOrdered = $(this).find('.qtyOrdered input').val() * 1; qtyOrdered = Math.round(qtyOrdered); var qtyReturned = $(this).find('.qtyReturned input').val() * 1; qtyReturned = qtyReturned.toFixed(0); $(this).find('.qtyReturned input').val(qtyReturned); //Remove decimals from QTY ordered $(this).find('.qtyOrdered input').val(qtyOrdered); var disc = $(this).find('.disc input').val()/100*1; var totalPrice =0; //Calculate total price //Calculate Discount if more than 0% if (disc > 0) { disc = 1 - disc; if(uom == 100) { totalPrice = listPrice/100*qtyOrdered*disc; } else{totalPrice = listPrice * disc;} } else{totalPrice = listPrice/100;} var totalPriceRounded = totalPrice.toFixed(2); $(this).find('.totalPrice input').val(totalPriceRounded); subtotal += totalPrice / qtyOrdered * qtyReturned; subtotal = subtotal.toFixed(2); subtotalcredit += subtotal *1; //subtotalcredit = subtotalcredit.toFixed(2); $(this).find('.stock_subtotal input').val(subtotal); });//end for each tblstock function subtotalcredit = subtotalcredit.toFixed(2); $('.credit_subtotal input').val(subtotalcredit); $('.vat input').val(totalVAT); totalcredit += subtotalcredit *1; totalcredit = totalcredit.toFixed(2); //totalcredit = totalcredit.toFixed(2); $('.totalCredit input').val(totalcredit); }//end sumtotalcredit function });//end ready and end function
Thanks
Sheldon