0
我試圖根據搜索結果停止創建記錄。儘管我知道數據存在,但我似乎無法通過我的SuiteScript搜索返回任何數據。0從NetSuite搜索返回的結果
我創建了一個自定義保存的搜索,使用下面使用的確切過濾器並返回我正在尋找的結果。
爲什麼我可能沒有檢索到任何結果,有什麼突出嗎?
注意:sfdcAccountId變量確實有一個值,所以我正在搜索一個有效的值。
// 2.0
define(["N/error", "N/log", "N/search"], function (err, log, search) {
/**
* 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');
log.debug({
"title": "Before Submit",
"details": "sfdcAccountId=" + sfdcAccountId
});
if(sfdcAccountId == null || sfdcAccountId == '') return false;
var searchResult = search.create({
type: search.Type.CUSTOMER,
filters: ['custentitysfdc_account_id', search.Operator.IS, sfdcAccountId]
}).run();
return (searchResult != null && searchResult.length > 0);
}
exports.beforeSubmit = beforeSubmit;
return exports;
});