I'm trying to run what I think is a fairly simple script to do the following when an Invoice is submitted. Occurs for each line item on the Invoice:
- get serial number
- search for this serial number in Item Receipt records
- return the value of the field 'poastext' (purchase order number)
- put this value into a custom field on the line item in the invoice
This is so when we do reports on sales, we can reference the sale of an individual serialized item right back to the originating PO. Some vendors require this when we report sales back to them.
I am now running up against this usage limit of 100, and the test record only has two line items.
Here's the code.
function serial_po_search()
{
var inv_record = nlapiGetNewRecord();
var num_of_lines = inv_record.getLineItemCount('item');
for (i = 1; i <= num_of_lines; i++)
{
var line_serial_number = inv_record.getLineItemValue('item', 'serialnumbers', i);
// Initialize array for search filter
var filter = new Array();
filter[0] = new nlobjSearchFilter('serialnumber', null, 'contains', line_serial_number, null);
// Perform search
var searchresults = nlapiSearchRecord('itemreceipt', null, filter, null);
// Specify particular field from search results
var line_purchase_order = '';
for (i = 0; searchresults != null && i < searchresults.length; i++ )
{
var searchresult = searchresults[i];
line_purchase_order += searchresult.getValue('poastext');
}
inv_record.setLineItemValue ('item', 'custcolinternalpurchaseorder', i, line_purchase_order);
}
}
Any help greatly appreciated