Support has been helping us on this, but we need a fast answer. We can't get this site live because of this error.
We are using scriptable cart to automatically add an activation fee to the cart when certain items are purchased. It works well until the very last page, with the Submit Order button. It says Form Validation Failed.
I have checked the form used as the scripting template as well as the form used to create the sales order, and there are no mandatory fields that would cause this. I have also stripped the theme of all scripts, and it still fails.
I am wondering if it's getting caught in a loop despite the processing flag.
Here is the script:
function recalc(type, action) { if (type != 'item') { return; } try { var processing = nlapiGetFieldValue('custbody_processing'); if (processing != null && processing == 'T') { // We are in a secondary recalc, so exit return; } // If we've passed the previous check, we are in the first // level of recalc, so set processing flag nlapiSetFieldValue('custbody_processing', 'T'); // Ignore any add-to-carts that are not shoes var currentItemId = nlapiGetCurrentLineItemValue('item','item'); if(applicabilityCheck(currentItemId) == 0) { nlapiLogExecution("DEBUG", "Item 382 was not found..."); return; } if (action=='commit') { doCommit(); return true; } //REMOVE ITEM NOT WORKING IN THE SITE if (action=='remove') { doRemove(); return true; } } catch (err) { log("General Error: "+err.message); } finally { // Now, even with an error, we want to reset the processing flag // so use a finally-clause to ensure this happens no matter what nlapiSetFieldValue('custbody_processing', 'F'); } return true; } // Called when a commit is done for recalc function doCommit() { //var thisItem = nlapiGetCurrentLineItemValue('item','item'); var thisQty = nlapiGetCurrentLineItemValue('item','quantity'); nlapiLogExecution("DEBUG", "Adding an item... "); var activationId = '385'; var activationLine = findItem(activationId); if (activationLine == -1) { // We need to add a activation here nlapiLogExecution("DEBUG", "Adding activation since no line item found... "); addItem(activationId, thisQty); } else { var existingShoeQuantity = getShoeCount(); activationQty = nlapiGetLineItemValue('item', 'quantity', activationLine); nlapiLogExecution("DEBUG", "Updating the quantity for activation line... "); nlapiLogExecution("DEBUG", "activationLine on doCommit is"+activationLine); //if (activationQty != thisQty) //{ log("updating quantity of activation"); nlapiLogExecution("DEBUG", "activationLine inside docommit() " + activationLine); safeSelectLineItem(activationLine); nlapiSetCurrentLineItemValue('item', 'quantity', existingShoeQuantity); nlapiCommitLineItem('item'); //} } } // Called when a remove is done for recalc. function doRemove() { var existingShoeQuantity = getShoeCount(); //gets the number of line items nlapiLogExecution("DEBUG", "Removing item now..."); //var thisItem = nlapiGetCurrentLineItemValue('item','item'); //var thisQty = nlapiGetCurrentLineItemValue('item','quantity'); //log("Current qty of cert = "+thisQty); var activationId = '385'; var activationLine = findItem(activationId); //looks for the line item number of 385 if (activationLine == -1) { // No Activation line, so no need to remove log("Activation not found "); return; } nlapiLogExecution("DEBUG", "Updating activation line number " + activationLine); nlapiLogExecution("DEBUG", "existingShoeQuantity " + existingShoeQuantity); nlapiLogExecution("DEBUG", "activationLine " + activationLine); if (existingShoeQuantity == 0){ //meaning no line items nlapiLogExecution("DEBUG", "Removing existingShoeQuantity is 0"); safeSelectLineItem(activationLine); //nlapiSelectLineItem('item', activationLine); nlapiRemoveLineItem('item', activationLine); return; } else if (existingShoeQuantity > 0 && activationLine > 0 && existingShoeQuantity != activationLine ) { nlapiLogExecution("DEBUG", "(existingShoeQuantity > 0 && activationLine > 0 && existingShoeQuantity != activationLine)"); nlapiRemoveLineItem('item', activationLine); var activationId = '385'; addItem(activationId, existingShoeQuantity); } } // Sometimes, a selectLineItem results in an error if there's uncommitted // values in the item list. This makes sure this does not happen. function safeSelectLineItem(itemLine) { if (notEmpty(nlapiGetCurrentLineItemValue('item','item'))) { nlapiCommitLineItem('item'); } nlapiSelectLineItem('item', itemLine); } function getShoeCount() { var itemCount = nlapiGetLineItemCount('item'); //var lineNum = 0; var shoeQty = 0; for(var idx =1; idx<= itemCount; idx++) { var itemId = nlapiGetLineItemValue('item', 'item', idx); //var itemParent = nlapiLookupField('item', itemId, 'parent'); //if(itemId != '166') if(applicabilityCheck(itemId) == 0) continue; var itemQty = getFloat(nlapiGetLineItemValue('item', 'quantity', idx)); shoeQty+=itemQty; } return shoeQty; } // General find function for the item list function findItem(itemID) { var cnt = nlapiGetLineItemCount('item'); for (var i=1; i <= cnt; i++) { if (nlapiGetLineItemValue('item','item',i) == itemID) { return i; } } return -1; // -1 means not found } // This function adds the given item to the order function addItem(itemID, qty) { safeSelectNewLineItem(); nlapiSetCurrentLineItemValue('item', 'item', itemID); nlapiSetCurrentLineItemValue('item', 'quantity', qty); nlapiCommitLineItem('item'); } // Sometimes, a selectNewLineItem results in an error if there's uncommitted // values in the item list. This makes sure this does not happen. function safeSelectNewLineItem() { if (notEmpty(nlapiGetCurrentLineItemValue('item','item'))) { nlapiCommitLineItem('item'); } nlapiSelectNewLineItem('item'); } /******************************************************************************* * Name: applicabilityCheck * Purpose: *******************************************************************************/ function applicabilityCheck(itemInternalId) { var aeterexItems = ['382']; for (var arrIdx = 0; arrIdx < aeterexItems.length; arrIdx++){ if(aeterexItems[arrIdx] == itemInternalId) return 1; } return 0; } function log(msg) { alert(msg); } function isEmpty(tmp) { return tmp == null || tmp == ''; } function notEmpty(tmp) { return !isEmpty(tmp); } /******************************************************************************* * Name: getFloat * Purpose: Return the float value *******************************************************************************/ function getFloat(aValue){ if (aValue == null || isNaN(aValue) || aValue=='') return 0; return parseFloat(aValue); } Thanks so much for any help you can provide. This is driving me nuts!