We are having a Thanksgiving sale and I need to create a script that will add free bonus items to our web store orders based on their order total. Here was my original script:
function SalesOrder_beforeSubmit(type) { // Execute this only when Sales order is created if (type == 'create') { // just report that the type is create nlapiLogExecution('DEBUG', 'type argument', 'type is create'); // Get the current record var currentRecord = nlapiGetNewRecord(); // Get the order total var total = parseInt(currentRecord.getFieldValue("total")); nlapiLogExecution('DEBUG', 'order total', total); // Get the number of line items before submit var lines = currentRecord.getLineItemCount('item'); nlapiLogExecution('DEBUG', 'number of line items', lines); // Add a new line item for the coin figures based on the order total if ( total > 299 ) { currentRecord.selectNewLineItem('item'); currentRecord.setCurrentLineItemValue('item', 'item', 33); currentRecord.setCurrentLineItemValue('item', 'quantity', 12); currentRecord.setCurrentLineItemValue('item', 'amount', 0); currentRecord.commitLineItem('item'); nlapiLogExecution('DEBUG', 'added coin figures', '12'); } var id = nlapiSubmitRecord(currentRecord, true); } } I have also tried using the following for adding the item: if ( total > 299 ) { currentRecord.insertLineItem( 'item', lines + 1 ); currentRecord.setLineItemValue('item', 'item', lines + 1, 33 ); // 33 = coin figure internal id currentRecord.setLineItemValue('item', 'quantity', lines + 1, 12 ); currentRecord.setLineItemValue('item', 'amount', lines + 1, 0 ); nlapiLogExecution('DEBUG', 'added coin figures', '12'); } Anyway, I'm obviously doing something wrong. When I try to debug the script, everything runs fine until the submit line where it crashes with:RCRD_UNEDITABLE"That record is not editable."Can someone give me some sample code or explain what might be wrong with mine? It seems like a simple enough task, but I'm not having any luck with it... Thanks in advance!