【问题标题】:Passing script parameters传递脚本参数
【发布时间】:2018-08-10 04:41:29
【问题描述】:

我在用户事件脚本中传递脚本参数时遇到问题。我知道为什么我的代码失败了。有没有办法通过参数传递文本?

这是错误:

{"type":"error.SuiteScriptError","name":"INVALID_INITIALIZE_REF","message":"您无法初始化发票:无效引用 18349。","stack":["createError(N/error )","afterSubmit(/SuiteScripts/complexInvoice.js:29)"],"cause":{"type":"internal error","code":"INVALID_INITIALIZE_REF","details":"你不能初始化发票: 无效引用 18349。","userEvent":"aftersubmit","stackTrace":["createError(N/error)","afterSubmit(/SuiteScripts/complexInvoice.js:29)"],"notifyOff":false} ,"id":"","notifyOff":false}

这是代码:

/** * @NApiVersion 2.x * @NScriptType 用户事件脚本 * @NModuleScope 相同帐户 */ define(["N/record", "N/log", "N/runtime"], function (record, log, runtime) {

function afterSubmit(context) {

    // Gather your variables
    var newRec = context.newRecord;
    var freightCost = newRec.getValue({
        fieldId: 'custbody_freight_cost'
    });
    var freightItem = runtime.getCurrentScript().getParameter('custscript_freight_item');
    var handlingItem = runtime.getCurrentScript().getParameter('custscript_handling_item');
    var salesOrderId = newRec.getValue({
        fieldId: 'createdfrom'
    });
    log.debug('Sales Order ID', salesOrderId);
    log.error({
        title: 'Freight Cost',
        details: freightCost
    });
    log.error({
        title: 'Freight Item',
        details: freightItem
    });

    // Transform the Sales Order into an Invoice
    var invoiceRecord = record.transform({
        fromType: record.Type.SALES_ORDER,
        fromId: salesOrderId,
        toType: record.Type.INVOICE,
        isDynamic: true
    });
    log.error({
        title: 'Debug Entry',
        details: invoiceRecord
    });
    invoiceRecord.selectNewLine({
        sublistId: 'item'
    });
    invoiceRecord.setCurrentSublistText({
        sublistId: 'item',
        fieldId: 'item',
        text: freightItem
    });
    invoiceRecord.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'amount',
        value: freightCost
    });
    invoiceRecord.commitLine({
        sublistId: 'item'
    });
    invoiceRecord.selectNewLine({
        sublistId: 'item'
    });
    invoiceRecord.setCurrentSublistText({
        sublistId: 'item',
        fieldId: 'item',
        text: handlingItem
    });
    invoiceRecord.commitLine({
        sublistId: 'item'
    });

    // Here is how you set a body field
    invoiceRecord.setValue({
        fieldId: 'custbody_freight_cost',
        value: freightCost,
        ignoreFieldChange: true
    });

    // Submit the record
    var rid = invoiceRecord.save();
    log.debug('Saved Record', rid);
}
return {
    afterSubmit: afterSubmit 
    };

});

【问题讨论】:

  • 为什么你的代码失败了?如果您知道,请提及?

标签: netsuite suitescript2.0


【解决方案1】:

您的销售订单18349 可能处于不适合开具发票的状态,例如待批准。

【讨论】:

    【解决方案2】:

    检查一次它可能有效。

    要解决此问题,请导航至: (1) 设置 > 会计 > 首选项 > 设置会计 > 订单管理选项卡 > 开票 (2) 启用发货前发票首选项 (3) 保存首选项

    保存首选项后,上面的示例脚本应该可以转换销售订单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 2019-11-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多