0
votes

I'm currently having some trouble with Client-Side Scripting of an Inventory Detail Subrecord on an Assembly Build. As you know, Assembly Builds have two Inventory Details. The one in the top right corner works as expected, and I can access every field with Suitescript.

I'm having trouble with the bottom Inventory Detail though. I'm able to access it and use nlapiGetFieldValue() just fine. However, when I access the sublist, I am only able to look up the value of 'id'.

These are the fields that are supposed to exist, along with a less documented one called "receiptinventorynumber".

List of inventory assignment fields

Here is my code:

//get the line items in the bottom inventory details
var bottom_line_items = [];
for(var line_index = 0; line_index < nlapiGetLineItemCount("component"); line_index++)
{
    var bottom_inv_detail = nlapiViewLineItemSubrecord("component", 'componentinventorydetail', line_index+1);
    if(bottom_inv_detail != null)
    {
        var bottom_line_count = bottom_inv_detail.getLineItemCount('inventoryassignment');
        for(var index =0; index < bottom_line_count; index++)
        {
            bottom_inv_detail.selectLineItem('inventoryassignment', index+1);
            var sn = bottom_inv_detail.getCurrentLineItemValue('inventoryassignment', 'receiptinventorynumber');
            bottom_line_items.push(sn);
        }
    }
}
console.log(bottom_line_items);

Here is the result of executing it in the browser console:

enter image description here

As you can see, 'id', and 'internalid' work. 'receiptinventorynumber' does not. Neither do any of the other fields.

Because of my use case, I cannot wait for the record to be saved on the server. I have to catch this client side. Any suggestions are appreciated.

2

2 Answers

1
votes

It has been a long time since I have worked with Inventory Detail subrecord, but I think there is another field called 'assigninventorynumber'. Have you tried using that?

1
votes

Just was able to answer my own question, but it did end up involving a server-side search. I'm pretty sure it works as I wanted it to, but I am still involved in testing it. In essence, I grabbed the field 'issueinventorynumber', which had an id. That id was the internalid of a 'Inventory Serial Number', which I was able to perform a search for to get the actual number. Here's the resulting code:

//get the line items in the bottom inventory details
var bottom_line_ids = [];
for(var line_index = 0; line_index < nlapiGetLineItemCount("component"); line_index++)
{
    var bottom_inv_detail = nlapiViewLineItemSubrecord("component", 'componentinventorydetail', line_index+1);
    if(bottom_inv_detail != null)
    {
        var bottom_line_count = bottom_inv_detail.getLineItemCount('inventoryassignment');
        for(var index =0; index < bottom_line_count; index++)
        {
            bottom_inv_detail.selectLineItem('inventoryassignment', index+1);
            var sn = bottom_inv_detail.getCurrentLineItemValue('inventoryassignment', 'issueinventorynumber');
            bottom_line_ids.push(sn);
        }
    }
}

//do search to identify numbers of bottom serial numbers
var columns = [new nlobjSearchColumn('inventorynumber')];
var filters = []
for(var index = 0; index < bottom_line_ids.length; index++)
{
    filters.push(['internalid', 'is', bottom_line_ids[index]]);
    filters.push('or');
}
//remove the last 'or'
if(filters.length > 0)
{
    filters.pop();
}
var search = nlapiCreateSearch('inventorynumber', filters, columns);
var results = search.runSearch().getResults(0,1000);
bottom_line_items = []
if(results.length != bottom_line_ids.length)
{
    //if you get to this point, pop an error as the 'issueinventorynumber' we pulled is associated with multiple serial numbers
    //you can see which ones by doing a 'Inventory Serial Number' Saved Search
    //this is a serious problem, so we'd have to figure out what to do from there
}
for(var index = 0; index < results.length; index++)
{
    bottom_line_items.push(results[index].getValue('inventorynumber'));
}
console.log(bottom_line_items);