On an invoice created from a sales order the Created From field is not populated.
An invoice can be created in the UI from a sales order by clicking the Bill button or by script through the usage of nlapiTransformRecord. In both cases the Created From field maintains the link to the sales order from which the invoice was created, only if at least one of the initially present line items is still present when the record is submitted.
If after creating the invoice from the sales order and before submitting the invoice all line items are removed and new ones are added, then the Created From field is not populated with the reference to the original sales order.
For example, the following snippet creates an invoice linked through the Created From field to the sales order:
var salesOrderId = '123456'; //sample approved sales order, not yet billed var invoice = nlapiTransformRecord('salesorder', salesOrderId, 'invoice'); var lineItemCount = invoice.getLineItemCount('item'); for (var i=1; i < lineItemCount; i++) //looping until the last but one line item invoice.removeLineItem('item', 1); var invoiceid = nlapiSubmitRecord(invoice);However, the following code snippet creates an invoice, but the invoice's Created From field does not contain a reference to the sales order:
var salesOrderId = '123456'; //sample approved sales order, not yet billed var invoice = nlapiTransformRecord('salesorder', salesOrderId, 'invoice'); var lineItemCount = invoice.getLineItemCount('item'); for (var i=1; i <= lineItemCount; i++) //looping until the last line item invoice.removeLineItem('item', 1); //adding a new line item in order to successfully submit the record (according to the setup of the item and of the account other fields might need to be populated) var itemId = '789'; invoice.selectNewLineItem('item'); invoice.setCurrentLineItemValue('item', 'item', itemId); invoice.commitLineItem('item'); var invoiceid = nlapiSubmitRecord(invoice);
DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Netsuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.Netsuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Netsuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.Netsuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.