Reputation: 3
Trying to source a value from a custom record and set it in a field of new Lot Numbered Assembly/Bill of Material item. Half way through get this error when launching a search to retrieve the value. Search filters compare 2 values on the Item's record to identical values in the list of the custom record. Previous lines execute without errors. Any suggestion on how to address it. Thank you.
/**
* @NApiVersion 2.x
* @NScriptType WorkflowActionScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/runtime', 'N/search'],
/**
* @param {search} search
*/
function(search) {
/**
* Function to be executed when field is changed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
* @param {number} scriptContext.lineNum - Line number. Will be undefined if not a
sublist or matrix field
* @param {number} scriptContext.columnNum - Line number. Will be undefined if not a
matrix field
*
* @since 2015.2
*/
function onAction(scriptContext) {
var rec = scriptContext.newRecord;
//Get the Item's Division value
var itemDivision = rec.getValue('class');
log.debug({
title: "Get Item Division",
details: itemDivision
});
//Get the Item's Business Function value
var itemBusinessFunction = rec.getValue('custitem_swr_business_function');
log.debug({
title: "Get Item Business Function",
details: itemBusinessFunction
});
if(itemDivision !== '' && itemDivision !== null){
//Look up Item Approver Function using Item's Division and Item's Business Function
var results = search.create({
type: 'customrecord_swr_next_approver',
filters: [
{
name: 'class',
operator: 'is',
values: [itemDivision]
}, {
name: 'custrecord_swr_business_function',
operator: 'is',
values: [itemBusinessFunction]
}]
})
.run()
.getRange({start: 0, end: 1});
var itemApproverFunction = (results.length > 0) ? results[0].id : '';
log.debug({
title: "Get Approver Function",
details: itemApproverFunction
});
//Apply acquired Item Number in transaction
rec.setValue(itemApproverFunction);
}
}
return {
onAction: onAction
};
});
Upvotes: 0
Views: 1110
Reputation: 8847
You've mismatched your dependencies and their aliases in your define
statement. The parameters of the callback function correspond to the element in the same place in the dependency list. So your define
:
define(['N/record', 'N/runtime', 'N/search'],
function(search) {
is aliasing the N/record
module as search
, then not aliasing the other dependencies at all.
Instead, you'll need something like:
define(['N/record', 'N/runtime', 'N/search'],
function(record, runtime, search) {
Upvotes: 2