skip to Main Content

I’m encountering an error related to tax codes when creating orders using SuiteScript. The error message indicates an issue with an invalid tax code, specifically "TW5". Here’s the detailed error message:

{
   type: "error.SuiteScriptError",
   name: "INVALID_TAX_CODES",
   message: "Invalid Tax Code(s): TW5 -- valid ",
   ,
   
      notifyOff: false
   },
   notifyOff: false,
   userFacing: true
}

Below is the part of the code where the tax code is set:

javascript

function createOrder(jsonData, mappingData) {
    try {
        var salesOrder = record.create({
            type: record.Type.SALES_ORDER,
            isDynamic: true
        });

        // Set various other fields...

        if (jsonData['商品信息']) {
            jsonData['商品信息'].forEach((item, index) => {
                var itemId = getItemId(item['商品貨號']);
                if (itemId) {
                    salesOrder.selectNewLine({ sublistId: 'item' });
                    // Set item details including quantity and adjusted price...
                    salesOrder.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'taxcode',
                        value: 1902  // Is this where the error is occurring?
                    });

                    salesOrder.commitLine({ sublistId: 'item' });
                } else {
                    log.error('商品编码未找到', item['商品貨號']);
                }
            });
        }

        // Process mapping and save record...
        var recordId = salesOrder.save({
            enableSourcing: true,
            ignoreMandatoryFields: false
        });
        log.debug('销售订单已创建', 'ID: ' + recordId);
    } catch (e) {
        log.error({
            title: '创建订单时出错',
            details: e
        });
    }
}

I am not sure if the tax code ‘1902’ used here is correct. Could it be that this tax code is not recognized or valid in the system, or should I be handling this differently?

I have no problem creating orders in the UI interface, but I encounter this issue when creating sales orders in SuiteScript code.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I've identified the specific cause of the problem, but I'm still not sure why it's occurring. Instead of using a mapping approach, I tried setting the values one by one. Eventually, I found that setting 'trandate' specifically causes this error message.


  2. Tax Code list can be found under Setup > Accounting > Tax Codes. Check for 1902 if this Tax Code is valid for your Customer. Try to create a Sales order in UI first and check the available tax code for this customer.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search