This topic contains 2 replies, has 0 voices, and was last updated by krobinson98 8 years ago.
-
AuthorPosts
-
October 24, 2016 at 12:14 pm #1639
krobinson98I created a simple custom module to get an example working to pull into a RESTlet. I keep getting the error, org.mozilla.javascript.EcmaError: TypeError: Cannot find function libTest1 in object [object Object] when calling a function in my custom module. I am not sure how to get around this error, any ideas?
Custom Module:
/**
* TestModule.js
* @NApiVersion 2.x
* @NModuleScope SameAccount
*/
define([], function(){
function test1(){
return ‘hi’;
}
return {
libTest1 : test1
}
});
RESTlet:
define([‘N/record’, ‘N/error’, ‘./TestModule’],
function(record, TestModule) {
/**
* Function called upon sending a GET request to the RESTlet.
*
* @param {Object} requestParams – Parameters from HTTP request URL; parameters will be passed into function as an Object (for all supported content types)
* @returns {string | Object} HTTP response body; return string when request Content-Type is ‘text/plain’; return Object when request Content-Type is ‘application/json’
* @since 2015.1
*/
function doGet(requestParams) {
var test = TestModule.libTest1();
return ‘hi’;
}
…
return {
‘get’: doGet,
put: doPut,
post: doPost,
‘delete’: doDelete
};
});
This is a cached copy. Click here to see the original post. -
October 24, 2016 at 12:26 pm #1640
errolyou loading in N/error module where you are referencing TestModule. Should be:
Code:
define([‘N/record’, ‘N/error’, ‘./TestModule’],function(record, error, TestModule){
/**
* Function called upon sending a GET request to the RESTlet.
*
* @param {Object} requestParams – Parameters from HTTP request URL; parameters will be passed into function as an Object (for all supported content types)
* @returns {string | Object} HTTP response body; return string when request Content-Type is ‘text/plain’; return Object when request Content-Type is ‘application/json’
* @since 2015.1
*/
function doGet(requestParams){
var test = TestModule.libTest1();
return ‘hi’;
}…
return {
‘get’: doGet,
put: doPut,
post: doPost,
‘delete’: doDelete
};});
-
October 24, 2016 at 1:28 pm #1641
krobinson98That fixed it, thanks.
-
AuthorPosts
You must be logged in to reply to this topic.