I am having trouble understanding what this error means.
org.mozilla.javascript.EcmaError: ReferenceError: "nlapiSearchRecord" is not defined. (/SuiteScripts/PreventDuplicateCustomer.js#35)
I am attempting to create a script which searches for a duplicate record based on a specific field which is supposed to be unique. I would like to prevent creating duplicate 'CUSTOMER' records in NetSuite using the following script. '
Does anyone see anything that jumps of the page as wrong with the code below?
// 2.0
define(["N/error", "N/log"], function (err, log) {
/**
* User Event 2.0 example showing usage of the Submit events
*
* @NApiVersion 2.x
* @NModuleScope SameAccount
* @NScriptType UserEventScript
* @appliedtorecord customer
*/
var exports = {};
function beforeSubmit(scriptContext) {
log.debug({
"title": "Before Submit",
"details": "action=" + scriptContext.type
});
if (doesCustomerExist(scriptContext)) {
throw err.create({
"name": "DUPLICATE_SFDC_ACCOUNT_ID",
"message": "Customer Already Contains SFDC Account Id",
"notifyOff": true
});
}
}
function doesCustomerExist(scriptContext) {
var sfdcAccountId = scriptContext.newRecord.getValue('custentitysfdc_account_id');
if(sfdcAccountId == null || sfdcAccountId == '') return false;
var searchFilter = new nlobjSearchFilter('custentitysfdc_account_id', null, 'is', sfdcAccountId, null);
var searchResult = nlapiSearchRecord('customer', null, searchFilter, null);
return (searchResult != null && searchResult.length > 0);
}
exports.beforeSubmit = beforeSubmit;
return exports;
});