【问题标题】:NetSuite: How can I add a record to a Advanced PDF/HMTL Template?NetSuite:如何向高级 PDF/HTML 模板添加记录?
【发布时间】:2023-01-31 00:41:09
【问题描述】:

所以我知道我可以使用 N/render 来生成一个模板,我可以使用 addRecord 将记录对象添加到打印模板以使其在 FTL 中可用。

我的问题是,当单击本机打印按钮并打印高级 PDF/HTML 模板时,我是否可以做类似的事情。我知道我可以在用户事件脚本中捕获 PRINT 事件,但除此之外我就卡住了。

我知道这个问题有点笼统,我会根据要求添加上下文。我只是不知道该走哪条路。

编辑:我熟悉将 custpage 字段添加到表单然后在 FTL 中提取 JSON 的选项。 在这种特定情况下,如果我可以简单地添加一条完整记录,会方便得多。意思是我在 Item Fulfillment 印刷品上,想要将完整的父销售订单记录添加到印刷品中,以便我可以通过 salesorder.memo 等在 FTL 中访问它。类似于:

require(['N/render'], function(render) {
   var renderer = render.create();
   renderer.addRecord('customer', record.load({ type: record.Type.CUSTOMER, id: customer }));
})

问题是我只知道如何为完全自定义的打印件执行此操作,但不知道如何从交易中的本机打印按钮打印的打印件。 我需要这样做来进行从销售订单行到项目履行行的行匹配,如果可能的话,我宁愿这样做,而不是创建客户页面并插入定制对象。

【问题讨论】:

    标签: netsuite suitescript suitescript2.0


    【解决方案1】:

    我指的是one of my previous answer

    使用 UserEventScript 中的 beforeLoad 挂钩在 context.form 上设置额外数据。您将能够在模板上访问此数据。

    /**
     * @NApiVersion 2.x
     * @NScriptType UserEventScript
    */
    define(['N/ui/serverWidget'], function(serverWidget) {
    
      function beforeLoad(context) {
    
        // var request = context.request;
        // var newRecord = context.newRecord;
    
        var form = context.form;
        var type = context.type;
        var UserEventType = context.UserEventType;
    
        // only execute during printing...
        if (type != UserEventType.PRINT) return
        
        var customData = {
           hello: 'world'
        }
    
        var field = form.addField({
          id : 'custpage_custom_data',
          label: 'Custom Data',
          type : serverWidget.FieldType.LONGTEXT
        });
    
        field.defaultValue = JSON.stringify(customData); 
    
      }
    
      return {
        beforeLoad: beforeLoad
      };
    
    })
    

    您可以通过以下方式访问模板中的数据:

    <#if record.custpage_custom_data?has_content>
    <#assign custom_data = record.custpage_custom_data?eval />
    </#if>
    
    

    【讨论】:

    • 谢谢,感谢您的帮助。我实际上对此很熟悉,但我试图为这种特定情况找到不同的解决方案。我对我的问题进行了编辑,以更好地解释它。
    【解决方案2】:

    根据您的问题,您还想在打印项目履行时从销售订单中添加项目子列表数据。如果是这样,那么我在这里使用了相同的情况。 脚步:-

    • 仅在打印模式下加载脚本之前编写用户事件,然后创建保存的搜索以获取项目的数据并将其保存在带有长文本类型的自定义字段中,并以空格作为标签。
    • 自定义附加到项目履行记录的标准 pdf 模板。 GoTo- customization- forms- Advanced pdf template-Customize preferred template for item fulfillment.
    • 在那里添加一个带有该自定义字段的表格。

    它会在标准打印按钮.我已经完成了工单记录。您可以使用销售订单保存的搜索在搜索中进行编辑。

    用户事件

    /**
     *@NApiVersion 2.x
     *@NScriptType UserEventScript
     */
     define(['N/record', 'N/search', 'N/ui/serverWidget'], function (record, search, serverWidget) {
        function beforeLoad(scriptContext) {
           try {
     
              if (scriptContext.type == 'print') {
                 var currentRec = scriptContext.newRecord;
                 var recid = currentRec.id;
     
                 columns[0] = search.createColumn({
                    name: "sequence",
                    join: "manufacturingOperationTask",
                    sort: search.Sort.ASC,
                    label: "Operation Sequence"
                 });   
     
                 columns[1] = search.createColumn({
                    name: "custevent_custom_op_name",
                    join: "manufacturingOperationTask",
                    label: "Operation Name(Instruction)"
                 });
                 columns[2] = search.createColumn({
                    name: "manufacturingworkcenter",
                    join: "manufacturingOperationTask",
                    label: "Manufacturing Work Center"
                 });
     
                 columns[3] = search.createColumn({
                    name: "formulanumeric",
                    formula: "Round({manufacturingoperationtask.runrate}*{quantity}/60,2)",
                    label: "BudgetHours"
                 });
     
                
                 //Creating search to get all the values for work order
                 var mySearch = search.create({
                    type: "workorder",
                    filters:
                       [
                          ["type", "anyof", "WorkOrd"],
                          "AND",
                          ["internalid", "anyof", recid],
                          "AND",
                          ["mainline", "is", "T"]
     
                       ],
                    columns: columns
                 });
                 var searchResultCount = mySearch.runPaged().count;
    
                 mySearch.run().each(function (result) {
                    // .run().each has a limit of 4,000 results
                    
                    results.push(result);
                    return true;
                 });
                 //populate current printout with custom record entries
                 var customRecords = { columns: columns, results: results };
     
                 var columns = customRecords.columns, results = customRecords.results;
     
                 var custrecord = scriptContext.form.addField({ id: 'custpage_custrecord_to_print', type: serverWidget.FieldType.LONGTEXT, label: " " }),
                    custrecordArray = [];
     
                 if (results && results instanceof Array) {
     
                    for (var i = 0; i < results.length; i++) {
     
                       var singleLine = {};
                       for (var j = 0; j < columns.length; j++) {
                          if (i == i && j == 2) {
                             var value = results[i].getText(columns[j]);
     
     
                          } else {
                             var value = results[i].getValue(columns[j]);
     
                          }
     
                          if (j == 0 || j == 1 || j == 2) {
                             if (value.indexOf('.') == 0 || value.indexOf(',') == 0 || value.indexOf('-.') == 0 || value.indexOf('-,') == 0) {
                                value = '0' + value;
     
                             }
     
                          }
                          singleLine["col" + j] = (value) ? value : '';
     
                       }
                       custrecordArray.push(singleLine);
                    }
                    custrecord.defaultValue = JSON.stringify(custrecordArray);
     
                 }
    
     
              }
     
           } catch (e) {
              log.error("ERROR", e);
           }
        
        
     
        }
     
        return {
           beforeLoad: beforeLoad,
        };
     });
    

    在高级 Pdf 模板中:-

    <#if record.custpage_custrecord_to_print?has_content>
      <#assign customrecord = record.custpage_custrecord_to_print?eval />
      <table width="100%" class="second_table" style="page-break-inside: auto; width: 100%; margin-top: 2px; padding-top: 0px">
        <#list customrecord as customrecord_line>
          <tr width="100%" border-top="solid black" margin-top="10px" style="margin-top:10px; page-break-before: auto;">
              <th width="25%" align="left" style="padding: 2px 2px;">Step</th>
              <th width="25%" align="center" style="padding: 2px 2px;">Activity</th>
            <th width="25%" align="center" style="padding: 2px 2px;">Run Rate(Min/Unit)</th>
              <th width="25%" align="center" style="padding: 2px 2px;">BudgetHours</th></tr>
        <tr width="100%" style="page-break-inside: auto;">
            <td width="25%" align="left" style="padding: 2px 2px;">0${customrecord_line.col0}</td>
            <td width="25%" align="center" style="padding: 2px 2px;">${customrecord_line.col2}</td>
          <td width="25%" align="center" style="padding: 2px 2px;">${customrecord_line.col3}</td>
            <td width="25%" align="center" style="padding: 2px 2px;">${customrecord_line.col4}</td>
         </tr>
            
    </list>
    </table>
    </#if>
    

    这会很有帮助。

    谢谢,

    【讨论】:

      猜你喜欢
      • 2018-02-28
      • 2018-10-20
      • 2019-07-18
      • 2017-02-19
      • 2014-05-08
      • 2020-12-26
      • 2018-01-10
      • 2022-12-04
      • 2020-01-11
      相关资源
      最近更新 更多