Saizou
Saizou

Reputation: 25

NetSuite : Auto Populate Line Item in Vendor Bill

Does anyone here have encounter a bug while auto-populating the line item in vendor bill?
I was trying to auto populate the line item base on my criteria fields.
Field A = Batch No.(A batch consist of items) - This items will only use for tagging.
Field B = Drop-down list of Item Category (consists of Item1, Item2, Item3 per category) - Main Item to be used.

e.g.
Selected the "Batch 1" = Sample Item 1, Sample Item 2, Sample Item 3
Selected the "Category 1" = Item1, Item2, Item3
Line Item will be:
Item1 -- Sample Item 1
Item1 -- Sample Item 2
Item1 -- Sample Item 3
Item2 -- Sample Item 1
Item2 -- Sample Item 2
Item2 -- Sample Item 3
Item3 -- Sample Item 1
Item3 -- Sample Item 2
Item3 -- Sample Item 3

Here's my sample code below:

var batchsearch = searchthisbatch(FieldA)
var categorysearch = searchthiscategory(FieldB)
var batchline = batchsearch.length;
var categoryline = categorysearch.length;
for (var bc=0; bc<batchline ; bc++){
    for (var cl=0; cl<categoryline ;cl++){
        var bcode = batchsearch[bc].getId()
        var clitem = categorysearch[cl].getValue('custrecord_categorylist');
        nlapiSelectNewLineItem('item');
        nlapiSetCurrentLineItemValue('item', 'item', clitem);
        nlapiSetCurrentLineItemValue('item', 'custcol_branchcode', bcode);
        nlapiSetCurrentLineItemValue('item','location',11);
        nlapiCommitLineItem('item');
    }
}

The code just works fine except the nlapiCommitLineItem('item'); Does anyone knows other code to commit the line item?

Hoping for your kind consideration and assistance on this.
Thanks in Advance.

<--Newbie here.. Sorry -->

Upvotes: 0

Views: 627

Answers (1)

bknights
bknights

Reputation: 15447

If this is a client script then you need to add two parameters to the nlapSetCurrentLineItemValue calls. Adding ,true, true will make the calls synchronous. Otherwise what is happening is that those calls are still executing when your code gets to nlapiCommitLineItem

You’ll probably also find you need to add a delay after commuting the line. This is a bit maddening as the amount of time is by trial and error and that function is also not synchronous and doesn’t have a callback.

Upvotes: 2

Related Questions