Netsuite 自定义打印按钮到 HTML 模板

问题描述 投票:0回答:1

我正在尝试在供应商退货授权或 VRMA 的查看模式下显示一个打印按钮,该按钮将打印用于标记的自定义 HTML 模板。

以下脚本已准备就绪。除了单击按钮时,一切看起来都在工作,我没有出现任何模板。

我得到的唯一错误是当我尝试从脚本部署中执行套件时

org.mozilla.javascript.EcmaError: ReferenceError: "customid" 未定义。 (/SuiteScripts/vrma_print_button_suitelet.js#17)

客户端脚本 名称:Vrma_print_button ID:customscript3535

`/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 * Version    Date            Author            Remarks
 * 1.00       27/02/2023      Rayne     Initial Development
 *
 * 
 */
`define(['N/url', 'N/currentRecord'], function(url, currentRecord) {

  var exports = {};

  function pageInit(context) {
    // TODO
  }

  function onButtonClick() {
    var suiteletUrl = url.resolveScript({
      scriptId: 'customscriptvrma_print_button_suitelet',
      deploymentId: 'customdeployvrma_print_button_suitelet',
      returnExternalUrl: false,
      params: {
        custom_id: currentRecord.get().id,
      },
    });

    window.open(suiteletUrl);
  }

  exports.onButtonClick = onButtonClick;
  exports.pageInit = pageInit;
  return exports;
});
``

姓名 vrma_print_button_suitelet ID customscript3536

`/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 * Version    Date            Author            Remarks
 * 1.00       27/02/2023      Rayne     Initial Development
 *
 * 
` */
    define(['N/render', 'N/record', 'N/xml'], function(render, record, xml) 
   {

  function onRequest(context) {

    var custom_id = context.request.parameters.custom_id;
    var pdfFileName = "VRMA Sticker";
    var renderer = render.create();
    var content = renderer.addRecord({
      templateName: 'record',
      record: record.load({
        type: record.Type.VENDOR_RETURN_AUTHORIZATION,
        id: custom_id
      })
    });
    renderer.setTemplateByScriptId("CUSTTMPL_113_5681957_SB1_699");
    context.response.setHeader({
      name: 'content-disposition',
      value: 'inline; filename="' + pdfFileName + '_' + custom_id + '.pdf"'
    });
    context.response.writeFile(renderer.renderAsPdf());
  }
  return {
    onRequest: onRequest
  }
  })

按钮正确出现, 我没有看到任何错误消息,它指向相关的 HTML 模板 ID:

但是当点击自定义打印按钮时,我没有得到任何结果。

我在上面的 3 个脚本中哪里出错了。 这是我第一次使用脚本,所以我对上面的内容是全新的。 我从下面的海报中改编了很多代码来满足我们的需求。

使用 Netsuite SuiteScripts 2.0 中的高级 PDF 模板将打印按钮添加到供应商积分(查看模式)

设置客户端、suitelet 和用户事件脚本、自定义 html 模板。

预计在点击按钮时会出现打印模板。

最新错误 3/4/23 更新 Suitelet 后。 {"type":"error.SuiteScriptError","name":"SSS_MISSING_REQD_ARGUMENT","message":"load: 缺少必需的参数:id","stack":["createError(N/error)","onRequest (/SuiteScripts/vrma_print_button_suitelet.js:17)","createError(N/error)"],"cause":{"name":"SSS_MISSING_REQD_ARGUMENT","message":"load: 缺少必需的参数:id"} “id”:“”,“notifyOff”:false,“userFacing”:true}

用户事件

define([], function() {

  var exports = {};

  function beforeLoad(context) {
    context.form.addButton({
      id: "custpage_vcpb",
      label: "Print",
      functionName: "onButtonClick"
    });
    context.form.clientScriptModulePath = "SuiteScripts/vrma_print_button_client.js";
  }

  exports.beforeLoad = beforeLoad;
  return exports;
});
pdf netsuite suitescript suitescript2.0
1个回答
0
投票

问题出在您的套件中的这一行:

var custom_id = context.request.parameters.customid;

这应该是: var custom_id = context.request.parameters.custom_id;

原因是由于您在客户端脚本中如何命名参数:

params: {
    **custom_id**: currentRecord.get().id,
}

您还需要相应地更新以下内容:

record: record.load({
    type: record.Type.VENDOR_RETURN_AUTHORIZATION,
    id: **custom_id**
  })
© www.soinside.com 2019 - 2024. All rights reserved.