file.load 返回“TypeError:无法调用方法“load”未定义的”在套房
问题:我试图查看文件柜中是否已存在文件。如果是这样,用户会收到警告。如果没有,则继续保存文件。这些组件的所有组件都可以工作,除了当我尝试加载文件时出现以下错误。
org.mozilla.javascript.EcmaError: TypeError: 无法调用未定义的“load”方法 (/SuiteScripts/suitelet_CheckIfFileExist.js#23)
我当前正在传递一个我知道存在的文件的文件 ID 进行测试,所以我知道我正在通过有效的文件 ID。
客户端脚本:
function checkIfFileExists(){
CallforSuitelet_CheckIfFileExist();
var result
if(result == true){
Ext.Msg.show({
title:'Overwrite File?',
msg: 'This existing file will be<br>overwritten:<br>' + msgBoxValue + '<br><br>Continue?',
width: 300,
icon: Ext.MessageBox.QUESTION,
buttons: Ext.MessageBox.YESNO,
fn: function(buttonId, value) {
if (buttonId == 'yes') {
CallforSuitelet();
console.log('Yes pressed');
} else {
Ext.Msg.show({
title:'Information',
msg: 'No files were copied.',
icon: Ext.MessageBox.INFO,
buttons: Ext.MessageBox.OK
});
console.log('No pressed');
}
}
});
}
}
}
function CallforSuitelet_CheckIfFileExist(){
console.log("CallforSuitelet_CheckIfFileExist function Entered")
var suiteletURL = url.resolveScript({
scriptId:'customscript_suitelet_checkiffileexist',// script ID of your Suitelet
deploymentId: 'customdeploy_suitelet_checkiffileexist',//deployment ID of your Suitelet
returnExternalURL: false,
params: {
'msgBoxValue':msgBoxValue
}
});
console.log("suiteletURL = " + suiteletURL);
https.get.promise({
url: suiteletURL
});
}
套件:
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/file', 'N/log'],
function(file, log) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
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 fileHasNoValue(fileId){
if (typeof fileId == 'undefined'){
return true;
}
if (fileId === null){
return true;
}
if (fileId === ''){
return true;
}
return false;
}
log.debug({details:'line beforefileOBj '})
var fileObj = file.load(288784)
//file.load({ <======= I have tried loading both ways
//id: 288784
//});
try{
var file = file.load({id: fileName});
contextResponse = fileHasNoValue(file);
} catch (e) {
log.error({
title: e.name,
details: e.message});
}
};
context.response.write(contextResponse)
return;
}
return {
onRequest: onRequest
};
});
Problem: I am trying to see if a file already exists in the file cabinet. If it does, the user gets a warning. If it does not, then the file proceeds to save. All components of these work except when I try to load the file I get the following error.
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "load" of undefined (/SuiteScripts/suitelet_CheckIfFileExist.js#23)
I am currently passing a file id of a file I know exist for testing so I know that I am passing a valid file id.
ClientScript:
function checkIfFileExists(){
CallforSuitelet_CheckIfFileExist();
var result
if(result == true){
Ext.Msg.show({
title:'Overwrite File?',
msg: 'This existing file will be<br>overwritten:<br>' + msgBoxValue + '<br><br>Continue?',
width: 300,
icon: Ext.MessageBox.QUESTION,
buttons: Ext.MessageBox.YESNO,
fn: function(buttonId, value) {
if (buttonId == 'yes') {
CallforSuitelet();
console.log('Yes pressed');
} else {
Ext.Msg.show({
title:'Information',
msg: 'No files were copied.',
icon: Ext.MessageBox.INFO,
buttons: Ext.MessageBox.OK
});
console.log('No pressed');
}
}
});
}
}
}
function CallforSuitelet_CheckIfFileExist(){
console.log("CallforSuitelet_CheckIfFileExist function Entered")
var suiteletURL = url.resolveScript({
scriptId:'customscript_suitelet_checkiffileexist',// script ID of your Suitelet
deploymentId: 'customdeploy_suitelet_checkiffileexist',//deployment ID of your Suitelet
returnExternalURL: false,
params: {
'msgBoxValue':msgBoxValue
}
});
console.log("suiteletURL = " + suiteletURL);
https.get.promise({
url: suiteletURL
});
}
Suitelet:
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/file', 'N/log'],
function(file, log) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
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 fileHasNoValue(fileId){
if (typeof fileId == 'undefined'){
return true;
}
if (fileId === null){
return true;
}
if (fileId === ''){
return true;
}
return false;
}
log.debug({details:'line beforefileOBj '})
var fileObj = file.load(288784)
//file.load({ <======= I have tried loading both ways
//id: 288784
//});
try{
var file = file.load({id: fileName});
contextResponse = fileHasNoValue(file);
} catch (e) {
log.error({
title: e.name,
details: e.message});
}
};
context.response.write(contextResponse)
return;
}
return {
onRequest: onRequest
};
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
去过那里,做过那件事。
通过使用 var 关键字,您将掩盖引用文件模块的变量。在 Javascript 中,var 关键字具有函数作用域,因此您所做的相当于:
其中一个应该有效:
或者
Been there, done that.
By using the var keyword you are overshadowing the variable that references the file module. In Javascript the var keyword has function scope so what you are doing is equivalent to:
Either of these should work:
or