Copy a Value to the Item Column
The following sample shows how to copy a value to the item column.
For the complete tutorial, see Copy a Value to the Item Column.
Important:
This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.
/**
* @NApiVersion 2.1
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/search'], (search) => {
function fieldChanged (context) {
try {
const recInvoice = context.currentRecord;
const stCurrField = context.fieldId;
const stCurrSublist = context.sublistId;
// Get UPC code of billing item
if (stCurrSublist === 'item' && stCurrField === 'custcol_billingitem') {
const billingitem = recInvoice.getCurrentSublistText({
sublistId: 'item',
fieldId: 'custcol_billingitem'
});
// Search for Item with Billing Item's UPC code
const itemSearch = search.create({
type: 'noninventoryitem',
filters: [
['upccode', 'is', billingitem]
],
columns: [
'upccode', 'itemid'
]
}).run();
// Set the UPC code text to the invoice
const result = itemSearch.getRange(0, 1);
const itemName = result[0].getValue(itemSearch.columns[1]);
recInvoice.setCurrentSublistText({
sublistId: 'item',
fieldId: 'item',
text: itemName
});
}
} catch (e) {
alert(e);
}
}
return {
fieldChanged: fieldChanged
};
});