【问题标题】:NetSuite - not able to reference images from folderNetSuite - 无法引用文件夹中的图像
【发布时间】:2016-10-04 09:37:03
【问题描述】:

我的代码:

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 硬编码用于测试目的。

问题是代码无法引用某些文件夹的图像。 就像我引用员工个人资料图片一样,它会引用他们,但对于某些文件夹,代码无法引用这些文件夹的图像。

我已检查这些文件夹不是私有的。请推荐

【问题讨论】:

    标签: javascript netsuite suitescript


    【解决方案1】:

    根据我的经验,我必须在需要在 PDF 中呈现的任何图像上设置“无需登录即可使用”。我无法解释为什么更深层次的原因。我只能告诉你我是如何解决这个问题的。

    我相信这与 NetSuite 实现 XML 到 PDF 生成器的方式有关。它似乎不在主脚本的相同上下文中运行。但就像我上面所说的,我不确定为什么。

    希望对您有所帮助。

    【讨论】:

    • 谢谢,我会调查的:)
    • 如果文件是 .pdf 那么有没有办法可以合并所有与费用相关的 .pdf 文件并生成一个 pdf 文件?
    • 有点,你应该从 BFO 研究 pdfset 标签。 BFO 是 NetSuite 使用的 xml 到 PDF 库。
    • @DeepakGarg 你能把我的答案标记为正确答案吗?
    猜你喜欢
    • 2014-08-04
    • 2017-05-13
    • 1970-01-01
    • 2018-12-30
    • 2013-11-04
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 2016-10-03
    相关资源
    最近更新 更多