netsuiteinvoicesuitescript2.0

How to fix 'Please enter a value for amount.' when creating NetSuite invoice with restlet?


I'm creating a NetSuite invoice in dynamic mode with SuiteScript 2.0, and when I run commitLine on my first item, it errors with 'Please enter a value for amount.' even though I have already supplied it using setCurrentSublistValue.

The relevant section of code is START CREATING ITEM through FINISHED CREATING ITEM, but I've included the full restlet in case the problem is in my setup.

Here's the JSON data I'm using to generate the item:

{"item":26,"amount":5706.48,"custcol_unit_price":"7.863035405","quantity":725735,"description":"July Impressions - 2019 Digital (April-July) - Custom Affinity (CAF) Dynamic CPM 7.5","line":1}

I'm logging a call to getCurrentSublistValue immediately after the setter, to ensure the system is accepting the value I send, and get 5706.48 back out for amount, so I believe setCurrentSublistValue is inserting it.

/**
 *@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
    };
  }
);

This is the error I'm seeing in the logs (line 34 is the commitLine call):

{"type":"error.SuiteScriptError","name":"USER_ERROR","message":"Please enter a value for amount.","stack":["anonymous(N/serverRecordService)","post(/SuiteScripts/api/submitInvoice.js:34)"],"cause":{"type":"internal error","code":"USER_ERROR","details":"Please enter a value for amount.","userEvent":null,"stackTrace":["anonymous(N/serverRecordService)","post(/SuiteScripts/api/submitInvoice.js:34)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}

Thanks in advance for any insight!


Solution

  • Try setting the quantity to 1. System might be overwriting your value with a calculated value of quantity * amount when you commit the line.