我在javascript AMD模塊中獲得了一些代碼。如果我創建一個引用它並部署它的ClientScript,當從ClientScript事件調用時,代碼運行良好。但是,如果我從自定義按鈕單擊事件中調用完全相同的函數,它會在require.js中引發意外錯誤(請參閱控制檯輸出的帖子末尾)。將模塊加載到自定義按鈕調用的客戶端腳本中
這裏的ClientScript代碼:
/**
* @NApiVersion 2.0
* @NScriptType ClientScript
* @NModuleScope public
*/
'use strict'
require.config({
paths: {
'iceUtil': 'SuiteScripts/ieCommon/iceUtil'
}
});
define(['N/log', 'iceUtil'], function (https, iceUtil) {
function calculateConfigurations() {
console.log('calculateConfigurations: before native log call');
log.debug({
title: 'calculateConfigurations',
details: 'nothing'
})
console.log('calculateConfigurations: before iceUtil log call');
iceUtil.logDebug('calculateConfigurations - iceUtil log',
'nothing');
}
function fieldChanged() {
iceUtil.logDebug('pageInit', 'begining client event');
calculateConfigurations();
iceUtil.logDebug('pageInit', 'ending client event');
}
return {
calculateConfigurations: calculateConfigurations
, fieldChanged: fieldChanged
}
});
iceUtil.js實際上只是包含本地NetSuite的日誌功能。
這工作正常,所有日誌顯示從fieldChanged事件觸發調用時。
但是,如果我將它連接到自定義按鈕,使用下面的代碼,只有第一個console.log('recordId: ' + recordId);
調用運行。第一次致電iceUtil.logDebug
炸彈。
下面是該線向上按鈕的代碼:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define(["N/log", "../ieCommon/iceUtil"], function (log, iceUtil) {
function addCalcConfigsButton(context) {
if(context.type==context.UserEventType.EDIT) {
context.form.clientScriptFileId = 6222;
//context.form.clientScriptModulePath = 'SuiteScripts/ieOppMetrics/clientCalculateConfigurations.js'; // This also works
context.form.addButton(
{
id : 'custpage_buttonid',
label : 'Calculate Configurations',
functionName : 'calculateConfigurations'
}
);
iceUtil.logDebug("addCalcConfigButton - iceUtil log",
"Button added.");
log.debug({
title: 'addCalcConfigButton - native log',
details: 'Button added.'
});
}
}
return {
beforeLoad : addCalcConfigsButton
};
});
下面是這段代碼的控制檯輸出時,它從fieldChanged事件調用和作品(日誌消息也顯示在NS執行日誌):
[Log] calculateConfigurations: before native log call
[Log] calculateConfigurations: before iceUtil log call
下面是從按下按鈕控制檯輸出和失敗(有在NS執行日誌沒有日誌消息):
[Log] calculateConfigurations: before native log call
[Error] UNEXPECTED_ERROR: Unexpected Error
onError (bootstrap.js:150)
onError (NsRequire.js:645)
check (NsRequire.js:994)
enable (NsRequire.js:1251)
init (NsRequire.js:882)
(anonymous function) (NsRequire.js:1547)
在你的客戶端腳本中,你需要'N/log'依賴,但是它在定義函數中的名字是'https'。 'log'沒有被定義。 –