为什么我的 Suitelet 返回未定义的响应

Why is my Suitelet returning Undefined response

我正在向 suitelet 发送请求 return 文件柜中是否存在文件。在服务器端似乎一切正常,但是当我到达客户端脚本时,我得到了未定义的对象 returned.

套房:

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
};

});

客户端脚本:

     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)
            });
    }

有时像这样的 shorthand 形式有效,但根据 API 文档,这个 return context.response.write(contextResponse); 应该是

context.response.write({output:contextResponse});

您得到的响应不仅仅是发送的正文,而是一个对象,例如:

ClientResponse: { 
code:number;
headers:object;
body:string;
}

所以

function (response) {
   console.log('response = ' + response)
})

应该是这样的:

function(response){
    console.log('response', response.body);
}