netsuiterestletinvoicesales-tax

Setting tax group for an invoice item line using a restlet


Working on an integration with an external system. The external system holds the details of the invoice. We create an invoice in Netsuite with summary information using a restlet.

One item is added to the invoice for services. Does anyone have insights on how to code the restlet to apply the tax group to the item?

I am getting the header and most of the line item information applied correctly in Netsuite, but cannot seem to get to the tax group so that the appropriate sales taxes are applied. Can do it manually. Note: tax groups, not tax codes, is important! See the variations tried below.

RESTLET CODE:

    var response = {};
    try {
      var recordType = requestBody.netsuite_record_type;
      var post_values = requestBody.values;

      var values = {};
      var keys = Object.keys(post_values);
      for (var i = 0, n = keys.length; i < n; i++) {
        var key = keys[i];
        var value = post_values[key];
        if (value && typeof value === 'object' && value.format) {

          if (_isDateValue(value)) {
            values[key] = _makeDateValue(value);
          } // else-if block removed here that handles images for another use case
        } else {
          values[key] = value;
        }
      }
      
      var newRecord = record.create({
        type: recordType,
        isDynamic: true
      });

      var fields = Object.keys(values);
      fields.forEach(function (field) {
        newRecord.setValue({fieldId: field, value: values[field]});
      });

      if (requestBody.lines && typeof requestBody.lines === 'object') {
        var postLines = requestBody.lines;

        postLines.forEach(function(postLine){
          var lineType = postLine.type;
          var lineValues = postLine.lineValues; // object

          newRecord.selectNewLine({
            sublistId: lineType
          });
          var lineFields = Object.keys(lineValues);
          lineFields.forEach(function(lineField){
            var thisValue = lineValues[lineField];
            if (_isDateValue(thisValue)) {
              thisValue = _makeDateValue(thisValue)
            };
            newRecord.setCurrentSublistValue({
              sublistId: lineType,
              fieldId: lineField,
              value: thisValue
              });
          });
          newRecord.commitLine({
            sublistId: lineType
            });
        });
      };

      newRecord.save({
        enableSourcing: false,
        ignoreMandatoryFields: true
      });

      response.newRecordId = newRecord.id;

    } catch (e) {
      response = {
        message: "An error occurred.",
        error: e
      };
    }

JSON FOR THE RESTLET CALL:

{
    "netsuite_record_type": "invoice",
    "values": {
        "trandate": {
            "format": "DATETIME",
            "value": "2024-09-15T21:00:00.000Z"
        },
        "tranid": "GCS Test RDU 09170938",
        "externalid": "GCS Test RDU 09170938",
        "entity": 120,
        "location": 2,
        "job": 25007,
        "terms": 2,
        "memo": "Test Work Description For Memo",
        "isTaxable": true
    },
    "lines": [
        {
            "type": "item",
            "lineValues": {
                "item": 623,
                "location": 2,
                "quantity": 1,
                "amount": 1000.00,
                "taxCode": 199,
                "isTaxable": true
            }
        }          
    ]
}

TRIED THESE VARIATIONS

This throws a "SSS_INVALID_SUBLIST_OPERATION" error

"lines": [
    {
        "type": "item",
        "lineValues": {
            "item": 623,
            "quantity": 1,
            "amount": 1000.00,
            "location": 2
        }
    },
    {
        "type": "taxItem",
        "lineValues": {
            "taxgroup": 199
        }
    }            
]

No error, but no tax group applied on all the following

"lines": [
    {
        "type": "item",
        "lineValues": {
            "item": 623,
            "quantity": 1,
            "amount": 1000.00,
            "location": 2,
            "taxCode": {"internalId": 199,
                "type": "taxGroup"}
        }
    }          
]
"lines": [
    {
        "type": "item",
        "lineValues": {
            "item": 623,
            "quantity": 1,
            "amount": 1000.00,
            "location": 2,
            "taxCode": 199
        }
    }          
]
        "lines": [
            {
                "type": "item",
                "lineValues": {
                    "item": 623,
                    "quantity": 1,
                    "amount": 1000.00,
                    "location": 2,
                    "taxCode": 199,
                    "isTaxable": true
                }
            }          
        ]

Solution

  • Through trial and error, the combination needed is to supply both the taxcode internal id value and the taxcode_display text value. The isTaxable field must not be referenced.