【问题标题】:How to fix 'Please enter a value for amount.' when creating NetSuite invoice with restlet?如何解决“请输入金额的值。”使用 restlet 创建 NetSuite 发票时?
【发布时间】:2019-08-29 18:16:21
【问题描述】:

我正在使用 SuiteScript 2.0 在动态模式下创建 NetSuite 发票,当我对我的第一个项目运行 commitLine 时,它​​会出现“请输入金额值”的错误。即使我已经使用 setCurrentSublistValue 提供了它。

相关的代码部分是从 START CREATING ITEM 到 FINISHED CREATING ITEM,但我已经包含了完整的 restlet,以防问题出在我的设置中。

这是我用来生成项目的 JSON 数据:

{"item":26,"amount":5706.48,"custcol_unit_price":"7.863035405","quantity":725735,"description":"7 月展示次数 - 2019 年数字版(4 月至 7 月) - 自定义关联度 (CAF ) 动态每千次展示费用 7.5","line":1}

我在 setter 之后立即记录对 getCurrentSublistValue 的调用,以确保系统接受我发送的值,并返回 5706.48 作为金额,所以我相信 setCurrentSublistValue 正在插入它。

/**
 *@NApiVersion 2.x
 *@NScriptType Restlet
 */
define(['N/record', 'N/error', 'N/log'],
  function(record, error, log) {
    function post(context) {
      log.audit("invoice", context);
      var rec = record.create({ type: "invoice", isDynamic: true });

      for (var fldName in context) {
        if (context.hasOwnProperty(fldName)) {
          if (fldName === "trandate") {
            rec.setValue(fldName, new Date(context[fldName]));
          } else if (fldName === "items") {
            var items = context[fldName]

            for (var idx in items) {
              var item = items[idx]
              // START CREATING ITEM
              log.audit('item', item)

              rec.selectNewLine({ sublistId: 'item' });
              for (var itemFldName in item) {
                log.audit(itemFldName, item[itemFldName])
                rec.setCurrentSublistValue({
                  sublistId: 'item',
                  fieldId: itemFldName,
                  value: item[itemFldName]
                })
                log.audit("current value", rec.getCurrentSublistValue({ sublistId: 'item', fieldId: itemFldName }))
              }

              rec.commitLine({ sublistId: 'item' });
              // FINISHED CREATING ITEM
            }
          } else {
            rec.setValue(fldName, context[fldName]);
          }

        }
      }
      var recordId = rec.save();

      return { success: true, message: recordId }
    }

    return {
      post: post
    };
  }
);

这是我在日志中看到的错误(第 34 行是 commitLine 调用):

{"type":"error.SuiteScriptError","name":"USER_ERROR","message":"请输入金额的值。","stack":["anonymous(N/serverRecordService)", "post(/SuiteScripts/api/submitInvoice.js:34)"],"cause":{"type":"internal error","code":"USER_ERROR","details":"请输入金额值.","userEvent":null,"stackTrace":["anonymous(N/serverRecordService)","post(/SuiteScripts/api/submitInvoice.js:34)"],"notifyOff":false},"id" :"","notifyOff":false,"userFacing":false}

提前感谢您的任何见解!

【问题讨论】:

  • 我刚刚尝试在金额前添加一个美元符号,这会将错误更改为:“您为以下字段输入了无效的字段值 $5706.48:金额”

标签: netsuite invoice suitescript2.0


【解决方案1】:

尝试将数量设置为 1。当您提交该行时,系统可能会使用 quantity * amount 的计算值覆盖您的值。

【讨论】:

  • 谢谢!不完全是这样,但我尝试在设置数量之前设置数量,并且它有效(数量为 1 和我需要的实际数量)。你是救生员。
【解决方案2】:

您先设置金额,然后设置数量,而不是设置费率。由于您在动态模式下处理记录,因此您需要按照与 UI 中完全相同的顺序设置字段值,否则您的数据将关闭。

如果您需要继续在动态模式下工作,那么您可能需要做一些事情:

  1. 通过将setCurrentSublistValue 的forceSyncSourcing 选项设置为true,确保在设置项目字段时进行采购。这应确保正确设置依赖于 Item 的所有列。
  2. 确保您以正确的顺序设置项目列;可能是项目,然后是数量,然后是数量。这样一来,动态模式应该不会重新计算您的金额。

我通常通过在标准模式而不是动态模式下工作来完全避免这个问题。我发现很少需要在动态模式下工作。在标准模式下,字段顺序不再重要,因为您在提交整个记录后让服务器计算出来,而不是在您设置每个字段时实时计算。

【讨论】:

  • 谢谢!我正在使用动态模式,因为他们文档中的所有示例都使用它,但标准模式似乎更简单。我目前在设置的顶级值(使用 record.setValue(fieldname, fieldvalue))被忽略时遇到问题。订购也可能是那里的问题吗?我按以下顺序添加它们:trandate、otherrefnum、tobeprinted、message、entity、customform、createdfrom 但 UI 导航 customform、entity、trandate、otherrefnum、tobeprinted、message
  • 这也是问题所在!我所有的数据现在都在正确流动。再次感谢!
  • 这是我的最佳答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-05
  • 2022-08-14
  • 1970-01-01
  • 2013-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多