NetSuite - 无法从文件夹中引用图像
NetSuite - not able to reference images from folder
我的代码:
function combineExpenseFiles(type){
try{
var currentRecordId = nlapiGetRecordId();
var currentRecord = nlapiLoadRecord('expensereport',currentRecordId);
var expensesLineItemCount = currentRecord.getLineItemCount('expense');
var template = '';
var fileParts = new Array();
template += '<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">\n';
template += '<pdf>\n<head>\n';
template += '</head>\n<body>\n';
flag=1;
for(var i=1;i<=expensesLineItemCount;i++){
var fileId = currentRecord.getLineItemValue('expense','expmediaitem',i);
var file = nlapiLoadFile(fileId);
var name = file.getName();
//var fileUrl = file.getURL();
nlapiLogExecution('DEBUG','online',file.isOnline());
var fileUrl = '/core/media/media.nl?id=36333&c=3960047&h=487697f81e113499d5f4';
template += '<img src="';
template += nlapiEscapeXML(fileUrl);
template += '" width="10%" height="10%"></img>\n<br></br><br></br>';
break;
}
template += '</body>\n</pdf>';
nlapiLogExecution('DEBUG','filename',template);
var renderer = nlapiCreateTemplateRenderer();
renderer.setTemplate(template);
//renderer.addRecord('url',url);
var xml = renderer.renderToString();
nlapiLogExecution('DEBUG','xml',xml);
var combinefile = nlapiXMLToPDF(xml);
combinefile.setEncoding('UTF-8');
combinefile.setName('expense_f.pdf');
nlapiLogExecution('DEBUG','file',combinefile);
combinefile.setFolder(2221); // Amit_Expenses
nlapiSubmitFile(combinefile);
}catch(error){
//nlapiLogExecution('DEBUG','error1',error.getDetails());
nlapiLogExecution('DEBUG','error',error.toString());
}
}
此代码的作用是获取与费用相关的所有 'jpeg' 文件并创建包含所有文件的模板并生成包含所有图像的 .pdf 文件。代码运行良好。
现在我已经将文件 url 硬编码用于测试目的。
问题是代码无法为某些文件夹引用图像。
就像我推荐员工个人资料图片一样,它会引用它们,但对于某些文件夹,代码无法引用这些文件夹的图像。
我已经检查过这些文件夹不是私人的。请建议
根据我的经验,我必须在需要在 PDF 中呈现的任何图像上设置 "Available Without Login"。我无法解释更深层次的原因。我只能告诉你我是如何解决这个问题的。
我认为这与 NetSuite 实现 XML PDF 生成器的方式有关。在主脚本的相同上下文中似乎没有 运行 。但是就像我上面说的,我不确定为什么。
希望这对您有所帮助。
我的代码:
function combineExpenseFiles(type){
try{
var currentRecordId = nlapiGetRecordId();
var currentRecord = nlapiLoadRecord('expensereport',currentRecordId);
var expensesLineItemCount = currentRecord.getLineItemCount('expense');
var template = '';
var fileParts = new Array();
template += '<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">\n';
template += '<pdf>\n<head>\n';
template += '</head>\n<body>\n';
flag=1;
for(var i=1;i<=expensesLineItemCount;i++){
var fileId = currentRecord.getLineItemValue('expense','expmediaitem',i);
var file = nlapiLoadFile(fileId);
var name = file.getName();
//var fileUrl = file.getURL();
nlapiLogExecution('DEBUG','online',file.isOnline());
var fileUrl = '/core/media/media.nl?id=36333&c=3960047&h=487697f81e113499d5f4';
template += '<img src="';
template += nlapiEscapeXML(fileUrl);
template += '" width="10%" height="10%"></img>\n<br></br><br></br>';
break;
}
template += '</body>\n</pdf>';
nlapiLogExecution('DEBUG','filename',template);
var renderer = nlapiCreateTemplateRenderer();
renderer.setTemplate(template);
//renderer.addRecord('url',url);
var xml = renderer.renderToString();
nlapiLogExecution('DEBUG','xml',xml);
var combinefile = nlapiXMLToPDF(xml);
combinefile.setEncoding('UTF-8');
combinefile.setName('expense_f.pdf');
nlapiLogExecution('DEBUG','file',combinefile);
combinefile.setFolder(2221); // Amit_Expenses
nlapiSubmitFile(combinefile);
}catch(error){
//nlapiLogExecution('DEBUG','error1',error.getDetails());
nlapiLogExecution('DEBUG','error',error.toString());
}
}
此代码的作用是获取与费用相关的所有 'jpeg' 文件并创建包含所有文件的模板并生成包含所有图像的 .pdf 文件。代码运行良好。
现在我已经将文件 url 硬编码用于测试目的。
问题是代码无法为某些文件夹引用图像。 就像我推荐员工个人资料图片一样,它会引用它们,但对于某些文件夹,代码无法引用这些文件夹的图像。
我已经检查过这些文件夹不是私人的。请建议
根据我的经验,我必须在需要在 PDF 中呈现的任何图像上设置 "Available Without Login"。我无法解释更深层次的原因。我只能告诉你我是如何解决这个问题的。
我认为这与 NetSuite 实现 XML PDF 生成器的方式有关。在主脚本的相同上下文中似乎没有 运行 。但是就像我上面说的,我不确定为什么。
希望这对您有所帮助。