Editing a Body Field Inventory Detail Subrecord Example
The following example loads an assembly build record. It also loads the subrecord stored in the assembly build’s Inventory Detail body field and saves a change to the subrecord.
To use this example, you must meet the following prerequisites:
-
The Advanced Bin / Numbered Inventory Management feature must be enabled at Setup > Company > Enable Features, on the Items & Inventory subtab.
-
The assembly build record that you load must already have an inventory detail subrecord.
-
The new value you choose for receiptinventorynumber must be unique in your system.
For general details on updating body field subrecords, see Using SuiteScript 2.x to Update a Body Field Subrecord.
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define([ 'N/record' ],function(record) {
function afterSubmit(context) {
// Load the record.
var rec = record.load({
type: record.Type.ASSEMBLY_BUILD,
id: 4918,
isDynamic: true
});
// Load the subrecord.
var subrec = rec.getSubrecord({
fieldId: 'inventorydetail'
});
// Identify a line on the subrecord's sublist.
subrec.selectLine({
sublistId: 'inventoryassignment',
line: 0
});
// Make changes to one sublist field.
subrec.setCurrentSublistValue({
sublistId: 'inventoryassignment',
fieldId: 'receiptinventorynumber',
value: '890123'
});
// Save the record.
try {
var recId = rec.save();
log.debug({
title: 'Record updated successfully',
details: 'Id: ' + recId
});
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
}
return {
afterSubmit: afterSubmit
};
});