admin管理员组文章数量:1023230
I am trying to create a custom profiler library to load into my SuiteScript 2.0 scripts. Its path is /SuiteScripts/profiler.js and my Suitelet is in /SuiteScripts/suitelet.js
Here how I am trying to load it into my suitelet:
define(['N/ui/serverWidget', 'N/log', 'N/file', './profiler'],
function(serverWidget, log, file, profiler) {
function onRequest(context) {
log.debug('profiler', profiler) // --> logs undefined
I've tried two approaches in profiler.js:
Approach #1:
function Profiler() {
var profileInstance = {};
// add methods to profileInstance
return profileInstance
}
Approach #2:
require([],
function() {
function profiler() {
var profilerInstance = {};
// add methods to profilerInstance
return profilerInstance;
}
return {
profiler: profiler
};
});
In Approach #2 I also added a ment indicating the SuiteScript version and require.config:
/**
*@NApiVersion 2.x
*/
require.config({
shim: {
'profiler': {
exports: 'profiler'
}
},
paths: {
profiler: '/SuiteScripts/Buy Request/profiler.js'
}
});
What am I doing wrong?
I am trying to create a custom profiler library to load into my SuiteScript 2.0 scripts. Its path is /SuiteScripts/profiler.js and my Suitelet is in /SuiteScripts/suitelet.js
Here how I am trying to load it into my suitelet:
define(['N/ui/serverWidget', 'N/log', 'N/file', './profiler'],
function(serverWidget, log, file, profiler) {
function onRequest(context) {
log.debug('profiler', profiler) // --> logs undefined
I've tried two approaches in profiler.js:
Approach #1:
function Profiler() {
var profileInstance = {};
// add methods to profileInstance
return profileInstance
}
Approach #2:
require([],
function() {
function profiler() {
var profilerInstance = {};
// add methods to profilerInstance
return profilerInstance;
}
return {
profiler: profiler
};
});
In Approach #2 I also added a ment indicating the SuiteScript version and require.config:
/**
*@NApiVersion 2.x
*/
require.config({
shim: {
'profiler': {
exports: 'profiler'
}
},
paths: {
profiler: '/SuiteScripts/Buy Request/profiler.js'
}
});
What am I doing wrong?
Share Improve this question asked Jun 8, 2016 at 17:41 Eric BrobergEric Broberg 413 bronze badges 2- What kind of errors are you getting? Have you tried inserting some logging mechanism to test if it's actually loading properly? That is, within the profiler itself... – TonyH Commented Jun 8, 2016 at 17:48
- log.debug('typeof profiler', typeof profiler) // --> also logs undefined. I need to get a function, or an object, loaded in as a starting point. I must not be wiring things up correctly. – Eric Broberg Commented Jun 8, 2016 at 19:12
1 Answer
Reset to default 8You need to use define
instead of require
to build your custom modules. Just change your Approach #2 to call define
instead of require
, and you should be good to go.
I am not sure whether require.config
works with SuiteScript or not. You shouldn't need it specifically for this use case.
I am trying to create a custom profiler library to load into my SuiteScript 2.0 scripts. Its path is /SuiteScripts/profiler.js and my Suitelet is in /SuiteScripts/suitelet.js
Here how I am trying to load it into my suitelet:
define(['N/ui/serverWidget', 'N/log', 'N/file', './profiler'],
function(serverWidget, log, file, profiler) {
function onRequest(context) {
log.debug('profiler', profiler) // --> logs undefined
I've tried two approaches in profiler.js:
Approach #1:
function Profiler() {
var profileInstance = {};
// add methods to profileInstance
return profileInstance
}
Approach #2:
require([],
function() {
function profiler() {
var profilerInstance = {};
// add methods to profilerInstance
return profilerInstance;
}
return {
profiler: profiler
};
});
In Approach #2 I also added a ment indicating the SuiteScript version and require.config:
/**
*@NApiVersion 2.x
*/
require.config({
shim: {
'profiler': {
exports: 'profiler'
}
},
paths: {
profiler: '/SuiteScripts/Buy Request/profiler.js'
}
});
What am I doing wrong?
I am trying to create a custom profiler library to load into my SuiteScript 2.0 scripts. Its path is /SuiteScripts/profiler.js and my Suitelet is in /SuiteScripts/suitelet.js
Here how I am trying to load it into my suitelet:
define(['N/ui/serverWidget', 'N/log', 'N/file', './profiler'],
function(serverWidget, log, file, profiler) {
function onRequest(context) {
log.debug('profiler', profiler) // --> logs undefined
I've tried two approaches in profiler.js:
Approach #1:
function Profiler() {
var profileInstance = {};
// add methods to profileInstance
return profileInstance
}
Approach #2:
require([],
function() {
function profiler() {
var profilerInstance = {};
// add methods to profilerInstance
return profilerInstance;
}
return {
profiler: profiler
};
});
In Approach #2 I also added a ment indicating the SuiteScript version and require.config:
/**
*@NApiVersion 2.x
*/
require.config({
shim: {
'profiler': {
exports: 'profiler'
}
},
paths: {
profiler: '/SuiteScripts/Buy Request/profiler.js'
}
});
What am I doing wrong?
Share Improve this question asked Jun 8, 2016 at 17:41 Eric BrobergEric Broberg 413 bronze badges 2- What kind of errors are you getting? Have you tried inserting some logging mechanism to test if it's actually loading properly? That is, within the profiler itself... – TonyH Commented Jun 8, 2016 at 17:48
- log.debug('typeof profiler', typeof profiler) // --> also logs undefined. I need to get a function, or an object, loaded in as a starting point. I must not be wiring things up correctly. – Eric Broberg Commented Jun 8, 2016 at 19:12
1 Answer
Reset to default 8You need to use define
instead of require
to build your custom modules. Just change your Approach #2 to call define
instead of require
, and you should be good to go.
I am not sure whether require.config
works with SuiteScript or not. You shouldn't need it specifically for this use case.
本文标签: javascriptCreate a custom library module in SuitScript 20Stack Overflow
版权声明:本文标题:javascript - Create a custom library module in SuitScript 2.0? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745597795a2158273.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论