file.load is returing "TypeError: Cannot call method "load" of undefined" on suitelet
file.load is returing "TypeError: Cannot call method "load" of undefined" on suitelet
问题:我正在尝试查看文件柜中是否已存在文件。如果是这样,用户会收到警告。如果没有,则文件继续保存。这些组件的所有组件都可以正常工作,但当我尝试加载文件时出现以下错误。
org.mozilla.javascript.EcmaError:类型错误:无法调用未定义的方法“加载”(/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
};
});
去过那里,做到了。
通过使用 var 关键字,您掩盖了引用文件模块的变量。在 Javascript 中,var 关键字具有函数作用域,因此您所做的相当于:
function(onContext){
var file;
if (context.request.method === 'GET') {
...
file = file.load... // if you look at it this way it's obvious that file no longer has a reference to the file module.
}
这些都应该有效:
file = file.load({id: fileName}); // file refers to the file module until it gets reassigned.
contextResponse = fileHasNoValue(file);
或
var myFile = file.load({id: fileId});
contextResponse = fileHasNoValue(myFile);
问题:我正在尝试查看文件柜中是否已存在文件。如果是这样,用户会收到警告。如果没有,则文件继续保存。这些组件的所有组件都可以正常工作,但当我尝试加载文件时出现以下错误。
org.mozilla.javascript.EcmaError:类型错误:无法调用未定义的方法“加载”(/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
};
});
去过那里,做到了。
通过使用 var 关键字,您掩盖了引用文件模块的变量。在 Javascript 中,var 关键字具有函数作用域,因此您所做的相当于:
function(onContext){
var file;
if (context.request.method === 'GET') {
...
file = file.load... // if you look at it this way it's obvious that file no longer has a reference to the file module.
}
这些都应该有效:
file = file.load({id: fileName}); // file refers to the file module until it gets reassigned.
contextResponse = fileHasNoValue(file);
或
var myFile = file.load({id: fileId});
contextResponse = fileHasNoValue(myFile);