Marty Zigman Marty Zigman
Prolecto Labs Accelerator Templates

How to Search for NetSuite Inventory Detail Records

NetSuite Reporting Technical

Tags: ,

This article is for the NetSuite SuiteScript programmers who are need to search on NetSuite’s Inventory Detail Records.

Background

The NetSuite Inventory Detail is effectively a ledger structure that is used to manage Serial and Lot Control Numbers on inventory transactions.  Often times, there is a need to extend this record type.  For example, we created a custom serialized asset manager application that links up to NetSuite Inventory Detail record structure.  Accordingly, we needed to update the Inventory Detail record to produce linkages from NetSuite Work Order Assembly operations to the key in our custom application.

The challenge is that this area of the NetSuite API is not well documented which effectively “blinded” one of our senior consultants.  However, he pushed through it (we nearly always do) through trial and error and perseverance.  We present you the following.

SuiteScript Search Pattern to Find Inventory Detail Record InternalIDs

var func = "SomeSuiteScriptRoutine;"
var assemblybuildid = 12333 // reference assembly build record

var AB = nlapiLoadRecord("assemblybuild",assemblybuildid);
var INVDTL = AB.viewSubrecord("inventorydetail");

//hunt for related inventory detail records
filters = [];
columns  = [];
filters.push(new nlobjSearchFilter('internalid', null, 'is', INVDTL.getFieldValue("id")));
columns.push(new nlobjSearchColumn('internalid',"inventorynumber"));

results = nlapiSearchRecord('inventorydetail', null, filters, columns) || [];

var inventoryNumberId;
if (results.length > 0) {
	//in our case, we expect only one
	inventoryNumberId = results[0].getValue("internalid","inventorynumber");
	nlapiLogExecution("DEBUG", func, "Assembly Build references Inventory Number " + inventoryNumberId);
} else {
	obj = {};
	obj.error = 'Could not find Inventory Number linked to Assembly Build';
	nlapiLogExecution("ERROR", func, obj.error);
	return obj;
};

//with the inventoryNumberId in hand, we can now load it perform our updates

Come Work with Us

If you love the NetSuite platform yet you feel undervalued by others for your problem solving capacities, perhaps we can work together. Our clients value NetSuite based innovation and leadership. Are you ready to raise your standards, serve others, and grow your career? If so, let’s have a conversation.

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - YouTube

About Marty Zigman

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

Biography • Website • X (Twitter) • Facebook • LinkedIn • YouTube

27 thoughts on “How to Search for NetSuite Inventory Detail Records

  1. Hi Marty,
    This is the great approach to filter out the NetSuite record based on InternalID, but NetSuite formula field has its own limitation of 1000 characters only.

    Any suggestion on this.

    Thanks

  2. Marty Zigman says:

    Hi Ravishanker,

    Wouldn’t we go into an expressions and use ORs to express criteria chunks?

    Marty

  3. Marty Zigman says:

    Hi Ravishanker,

    Wouldn’t we go into an expressions and use ORs to express criteria chunks?

    Marty

  4. Rajitha K S says:

    Hi,

    I tried to create a inventory transfer record from salesorder using suitescript.
    But when execute the script it displays the error “. ERROR: USER_ERROR – Please configure the inventory detail for this line.”.

    How we can configure it programatically?

    Could you please help me for this configuartion?

    Thanks

  5. Marty Zigman says:

    Rajitha,

    When you get USER_ERRORs, this is an indication you need more logic. In this case, it appears you are going to need to program the inventory sublist feature as you may be working with Bins, Lots, Serial Numbers. Are you able to follow it via the HELP?

    Marty

  6. Rajitha says:

    Hi ,
    My Problem is not solved. I want to set a serialized inventory item programaticaly using client. when i try to add an item into invoice, it shows the same error”please configure inventory detail for this line”.As per my knowledge i think we can’t create inventory detail in client script.how i can save this item without inventory detail.

    Could you please help me?

    Thanks,
    Rajitha K S

  7. Marty Zigman says:

    Hell Rijitha,

    We have updated the serial number field using 1.0 client side script. Here, we did it by adding lot numbers. The syntax is similar for serial numbers:

    nlapiSetCurrentLineItemValue(type,’serialnumbers’, lotnumber,false,false);

  8. Rajitha K S says:

    Thank you. I will try and let you know the result

  9. Rajitha K S says:

    Hi,

    is it possible to add multiple serial numbers for particular item using nlapiSetCurrentLineItemValue(type,’serialnumbers’, lotnumber,false,false);?

  10. Marty Zigman says:

    See this code example, as offered by Help and notice how they add more than one serial number.

    var record2= nlapiLoadRecord(‘purchaseorder’, id, {recordmode: ‘dynamic’});
    record2.selectLineItem(‘item’, 1);
    record2.setCurrentLineItemValue(‘item’, ‘quantity’, 2);

    var subrecord2= record2.editCurrentLineItemSubrecord(‘item’, ‘inventorydetail’);
    subrecord2.selectLineItem(‘inventoryassignment’, 1);
    subrecord2.setCurrentLineItemValue(‘inventoryassignment’, ‘issueinventorynumber’, ‘working123’);
    subrecord2.selectNewLineItem(‘inventoryassignment’);
    subrecord2.setCurrentLineItemValue(‘inventoryassignment’, ‘issueinventorynumber’,
    ‘2ndlineinventorynumber’);
    subrecord2.setCurrentLineItemValue(‘inventoryassignment’, ‘quantity’, ‘1’);
    subrecord2.commitLineItem(‘inventoryassignment’);

    subrecord2.commit();

    record2.commitLineItem(‘item’);

    var id = nlapiSubmitRecord(record2);

  11. Chris Fitch says:

    Wondering if there is a way to set a bin location on components in a lot numbered assembly

  12. Marty Zigman says:

    Have you looked at the inventoryassignment sublist on the Inventory Detail record object? You should be able to program against it to drive the bin number into a lot / serialized number record type.

  13. Quentin Pongrass says:

    Marty, sorry if this is not directly related to the topic, but how would you go about checking if the user has entered inventory detail on a TO item receipt via a client onsave script? I’ve tried >>>var invdetail = nlapiGetLineItemValue(‘item’,’inventorydetail’,i);<<< but get a nlobjError. I tried nlapiGetLineItemText but get null.

    This is confusing because "inventorydetail" is clearly on the item sublist according to the Record Browser (https://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_2/script/record/itemreceipt.html).

    Thanks for your time.

  14. Marty Zigman says:

    Lookup topic: Scripting the Inventory Detail Subrecord in the HELP. You can’t edit the inventory detail record in client side script.

  15. Quentin Pongrass says:

    I’m merely trying to verify the user has entered inventory detail on a TO receipt. NetSuite does this by putting a green check mark on the inventory detail icon. Is it possible to check for the green check?

  16. Marty Zigman says:

    Yes, you have to “break out” of NetSuite’s library and work the browser’s Document Object Model. We sometimes do this for our clients.

    Marty

  17. Quentin Pongrass says:

    Marty, I actually went a different route: view page source 🙂

    I sifted through the page source code and grabbed what I needed to make my onsave script run as follows:

    var linecount = nlapiGetLineItemCount('item'); for(i=1; i <= linecount; i++){ nlapiSelectLineItem('item', i) var itemtext = nlapiGetLineItemValue('item', 'item', i) try{ var invdetail_avail = nlapiGetCurrentLineItemValue('item', 'inventorydetailavail') var invdetail = nlapiViewCurrentLineItemSubrecord('item','inventorydetail'); var invdetail_linecount = invdetail.getLineItemCount('inventoryassignment'); for(var j = 1; j <= invdetail_linecount; j++){ invdetail.selectLineItem('inventoryassignment', j) var binnumber = invdetail.getCurrentLineItemValue('inventoryassignment', 'binnumber') var binqty = invdetail.getCurrentLineItemValue('inventoryassignment', 'quantity') console.log(invdetail_avail + ' ' + invdetail + ' ' + binnumber + ' ' + binqty) } }catch(err){ console.log(err) } }
  18. Marty Zigman says:

    That looks like a good code pattern! Great!

  19. How do I create inventory record to show batch number and lot number?

  20. Marty Zigman says:

    Hi Wanda,

    The Lot Number is via the inventory detail sublist. But what do you mean by batch? Are you using NetSuite Advanced Manufacturing?

    Marty

  21. Shanty says:

    Hi Marty,

    I want to fill/insert the inventory details in item fulfillment page using suitescript. Since I can’t create subrecord inventory detail with client script, I want using user event before submit script but the problem is when i click Save button there is alert that display i need to configure inventory details in line-i. Can you give me your suggestion how to handle this?Thank you before.

  22. Marty Zigman says:

    You should be able to via client script. Are you programming against the inventory detail record?

    See this code snippet on how to work with the inventory detail record which is where lots and serial numbers exist:


    //Set Inventory Detail data
    var invDetailSubrecord = REC.getSubrecord({ fieldId: 'inventorydetail' });

    setAssemblyInvDetailSubrecordHeader({
    invDetailSubrecord: invDetailSubrecord,
    qty: shipCartonQty,
    expiration: expiration,
    binLocation: binLocation,
    inventoryStatus: inventoryStatus,
    lotNumber: lotNumber
    });

    function setAssemblyInvDetailSubrecordHeader(invDetail) {
    var invDetailSubrecord = invDetail.invDetailSubrecord;
    var qty = invDetail.qty;
    var expiration = invDetail.expiration;
    var binLocation = invDetail.binLocation
    var inventoryStatus = invDetail.inventoryStatus;
    var lotNumber = invDetail.lotNumber;

    invDetailSubrecord.insertLine({
    sublistId: 'inventoryassignment',
    line: 0
    });

    var subrecordFieldsToSet = {
    'quantity' : qty,
    'expirationdate' : expiration,
    'binnumber' : binLocation,
    'inventorystatus' : inventoryStatus
    };

    util.each(subrecordFieldsToSet, function(value, fieldId){
    invDetailSubrecord.setSublistValue({
    sublistId: 'inventoryassignment',
    fieldId: fieldId,
    line: 0,
    value: value
    });
    log.debug(funcName + fieldId, invDetailSubrecord.getSublistValue({ sublistId: 'inventoryassignment', fieldId: fieldId, line: 0 }));
    });

    invDetailSubrecord.setSublistText({
    sublistId: 'inventoryassignment',
    fieldId: 'receiptinventorynumber', //Serial/Lot Number
    line: 0,
    text: lotNumber
    });
    }

  23. Shanty says:

    Hi Marty,

    Thanks for your answer. I just want to make sure if your answer can use for sublist subrecord? I need to fill the inventory detail for all items in Item Fulfillment/shipment page.

    And i read in your comment before that inventory details can’t edit in client script.

    Thank you

  24. Marty Zigman says:

    Hello Shanty,

    I believe you should be able to get control client-side. Make sure that you have the right data. Here is how you get to the inventory detail record:

    rec.getCurrentSublistSubrecord({ sublistId: ‘item’, fieldId: ‘inventorydetail’ })

    Marty

  25. John Fenton says:

    Marty been following you for years hoping you can help!

    I have custom “item number” fields for things like version and firmware since NS doesn’t have version control. I want users to enter that info on the inventory detail when receiving or assembling. Is it possible to script the inventory detail to allow users to enter that info in the native Inventory detail screen? The only thing I have found to work is setting on custom fields on the transaction line and an after-submit script to update the Lot Number after saving the receipt.

  26. Marty Zigman says:

    Hello John,

    Yes, you can get some control over the client scripting operation of the inventory detail record. I should probably write an article specifically on the client-side script patterns on inventory detail records. But we haven’t tried to modify the popup screen via script. I suspect we could ‘hack’ at it. Possibly consider this article to help with other code patterns:
    https://blog.prolecto.com/2018/12/08/learn-suitescript-2-0-pattern-for-netsuite-item-receipts-with-lot-serial-numbers/

    Marty

  27. Christopher says:

    Hi Marty,

    Thanks for this SS1 script. I rewrote it in SS2 but I get this error: “Your search contains a reference to join for which you do not have a permission: InventoryNumber”

    Any idea what permission I need?

    P.S. In attempt to discover the permission I tried a search of type search.Type.INVENTORY_NUMBER and got an error saying I needed Lists > Items but after adding that and retrying the original join-ed search I still get the same error.

    P.P.S. Here’s the essence of my SS2 version:
    const searchObj = search.create({
    type: search.Type.INVENTORY_DETAIL,
    filters: [
    search.createFilter({
    name: ‘internalid’,
    operator: search.Operator.IS,
    values: inventoryToEquipment.invDetailId
    })
    ],
    columns: [
    search.createColumn({
    name: ‘internalid’,
    join: search.Type.INVENTORY_NUMBER
    })
    ]
    });

Leave a Reply

Your email address will not be published. Required fields are marked *