我想創建一個自定義的剖析器庫加載到我的SuiteScript 2.0腳本。其路徑是/SuiteScripts/profiler.js和我Suitelet是/SuiteScripts/suitelet.js在SuitScript 2.0中創建一個自定義庫模塊?
在這裏,我如何我試圖將其加載到我suitelet:
define(['N/ui/serverWidget', 'N/log', 'N/file', './profiler'],
function(serverWidget, log, file, profiler) {
function onRequest(context) {
log.debug('profiler', profiler) // --> logs undefined
我在嘗試了兩種方法profiler.js:
方法#1:
function Profiler() {
var profileInstance = {};
// add methods to profileInstance
return profileInstance
}
方法2:
require([],
function() {
function profiler() {
var profilerInstance = {};
// add methods to profilerInstance
return profilerInstance;
}
return {
profiler: profiler
};
});
在方法#2我還添加了評論表示SuiteScript版本和require.config:
/**
*@NApiVersion 2.x
*/
require.config({
shim: {
'profiler': {
exports: 'profiler'
}
},
paths: {
profiler: '/SuiteScripts/Buy Request/profiler.js'
}
});
我在做什麼錯?
你會得到什麼樣的錯誤?你有沒有試過插入一些日誌記錄機制來測試它是否實際加載正確?也就是說,在探查器本身內... – TonyH
log.debug('typeof profiler',typeof探查器)// - >還記錄未定義。 我需要得到一個函數,或一個對象,作爲一個起點加載。我一定不能正確地接線。 –