Reputation: 99
I am sending a request to a suitelet to return whether or not a file exist in the file cabinet. Everything seems to work fine on the server side however when I get to the clientscript the I am getting, and undefined object returned.
Suitelet:
function onRequest(context) {
if (context.request.method === 'GET') {
var requestParam = context.request.parameters;
var fileName = 'Drag and Drop/Sales Order/' + requestParam.msgBoxValue + '.pdf';
var contextResponse = 'true';
function fileExist(fileId){
if (typeof fileId == 'undefined'){
return 'false';
}
if (fileId === null){
return 'false';
}
if (fileId === ''){
return 'false';
}
return 'true';
}
try{
file = file.load({id: fileName});
contextResponse = fileExist(file);
} catch (e) {
log.error({
title: e.name,
details: e.message});
}
};
return context.response.write(contextResponse);
}
return {
onRequest: onRequest
};
});
ClientScript:
function checkIfFileExists() {
//call suitelet
var suiteletURL = url.resolveScript({
scriptId:'customscript_suitelet_checkiffileexist',
deploymentId: 'customdeploy_suitelet_checkiffileexist',
returnExternalURL: false,
params: {
'msgBoxValue':msgBoxValue
}
});
https.get.promise({
url: suiteletURL
}).then(function (response) {
console.log('response = ' + response)
}).catch(function (reason) {
console.log('reason = ' + reason)
});
}
Upvotes: 1
Views: 1000
Reputation: 15447
Sometimes the shorthand form like this works but per the API docs this return context.response.write(contextResponse);
should be
context.response.write({output:contextResponse});
and the response you get is not just the body sent but is an object like:
ClientResponse: {
code:number;
headers:object;
body:string;
}
so
function (response) {
console.log('response = ' + response)
})
should be something like:
function(response){
console.log('response', response.body);
}
Upvotes: 1