I am trying to add several new lines to a proposal. Basically, we want to be able to choose an item and automatically populate several items below that one depending on how many items a customer has currently purchased. Reading what I just wrote confuses even me, so let me be less abstract. We are starting to offer some hosted solutions for our current customers and on new proposals, we would like to be able to select a new item called (for now) Convert to Cloud. Upon setting that item I need to loop through all of the modules of our software that the customer owns, place a new item in the proposal and what they currently pay so that we can then show them the savings they could have with the new solution.
I can do all of that so far except for adding multiple lines. So far it only adds one and it doesn't add a new one, it just changes the one I am on. Here is the code I have so far:
function postSource(type) { //nlapiLogExecution('DEBUG', 'Entered function', 'Enter'); //nlapiLogExecution('DEBUG', 'Type', 'Type = ' + type); if(type == 'item') { var lineitemid = nlapiGetCurrentLineItemValue('item', 'item'); var lineitemname = nlapiGetCurrentLineItemText('item', 'item'); var place = nlapiGetCurrentLineItemIndex('item'); // nlapiLogExecution('DEBUG', 'Item Id', 'id = ' + lineitemid); // nlapiLogExecution('DEBUG', 'Item Name', 'Name = ' + lineitemname); //Check to see if it is Cloud Environment Migration Item if(lineitemid == '873') { // Get customer id var custid = nlapiGetFieldValue('entity'); //nlapiLogExecution('DEBUG', 'Customer ID', 'Id = ' + custid); var rec = nlapiLoadRecord('customer', custid); // Count of install base items var count = rec.getLineItemCount('recmachcustrecord_install_base_bill_to_customer'); //nlapiLogExecution('DEBUG', 'Customer Item Count', 'Count = ' + count); for(var i = 1; i <= count; i++) { //nlapiInsertLineItem('item', count); nlapiLogExecution('DEBUG', 'Looping through customer Install Base items', 'i = ' + i); // Set new items nlapiSelectNewLineItem('item'); nlapiSetCurrentLineItemValue('item', 'item', 877); // Using a dummy description item nlapiSetCurrentLineItemValue('item', 'description', 'New description' + i); nlapiSetCurrentLineItemValue('item', 'amount', 0); nlapiCommitLineItem('item'); } } } // return true; } I have it set in the post sourcing event and I have also tried it in the validate line event. The debug log shows the loop executing the right amount of times, but clearly it is only adding the last one. How can I get it to work for multiple lines?