ANS-1524 · SUITESCRIPT DEVELOPMENT
How to Retrieve Clean Item Names from Item Receipts in NetSuite SuiteScript 2.x
Learn how to programmatically extract item names from item receipt records using modern SuiteScript, avoiding HTML formatting issues.
Short answer
When retrieving item names from item receipts in NetSuite using SuiteScript 2.x, utilize `record.load` and `getSublistValue`. Be aware that standard `itemname` fields may return HTML, while custom fields like `sitemname` (if present) might provide a clean text value. Remember SuiteScript 2.x sublist indexing is 0-based.
Scenario
NetSuite users developing SuiteScript solutions may encounter situations where retrieving the `itemname` field from an `itemreceipt` record's sublist returns HTML-wrapped text instead of a clean item name. This can complicate data processing and display, requiring a method to extract the plain text value.
Solution
The issue of itemname fields returning HTML can be addressed by using an alternative field or parsing the returned value. While the standard itemname field might contain HTML, a custom field, such as sitemname, if configured on the item record, may provide a clean text value. To retrieve the item name using SuiteScript 2.x, follow this approach:
javascript/** * @NApiVersion 2.x * @NModuleScope SameAccount */define(['N/record', 'N/log'], function(record, log) { function getItemNameFromItemReceipt(itemReceiptId) { try { var itemReceiptRecord = record.load({ type: record.Type.ITEM_RECEIPT, id: itemReceiptId, isDynamic: false }); // Note: 'sitemname' is typically a custom field. The standard 'itemname' field may return HTML. // SuiteScript 2.x uses 0-based indexing for sublists. var itemName = itemReceiptRecord.getSublistValue({ sublistId: 'item', fieldId: 'sitemname', line: 0 }); log.debug('Retrieved Item Name', itemName); return itemName; } catch (e) { log.error('Error retrieving item name', e); return null; } } return { getItemNameFromItemReceipt: getItemNameFromItemReceipt };});This example demonstrates loading an itemreceipt record and accessing the sitemname field from the 'item' sublist. Developers should verify field IDs using the SuiteScript Records Browser, as sitemname is not a standard NetSuite field and its availability depends on custom field configurations.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
