Hello, I am working on a script to create and edi...
# suitescript
n
Hello, I am working on a script to create and edit Vendor Bills / Purchase Orders under the SuiteTax Engine. For example, consider a document with two items: • SuiteTax Bullet 1 — assigned Tax First • SuiteTax Bullet 2 — assigned Tax Second Each item has its own tax When I create the document via script, everything works as expected — both items are added, and the taxdetails sublist contains correct taxcode, taxamount, and taxbasis values. When I edit the document and remove one of the items, it works correctly as well — the corresponding tax line is removed and totals are updated. However, when I edit the document and add an item (e.g., adding SuiteTax Bullet 2 back), I encounter an error: You have entered an Invalid Field Value 23667 (Tax Second) for the following field: taxcode This occurs even though the same taxCode (ID 23667 for “Tax Second”) works fine during initial creation.
Copy code
let document = record.load({ type: documentType, id: requestBody.id, isDynamic: false });
Copy code
if (isSuiteTaxEnabled) {
    document.setValue('taxdetailsoverride', true);
}

items.forEach((item, index) => {
    if (item.taxCode !== undefined && item.taxCode !== null) {
        document.setSublistValue({
            sublistId: 'taxdetails',
            line: index,
            fieldId: 'taxamount',
            value: item.taxAmount,
        });

        document.setSublistValue({
            sublistId: 'taxdetails',
            line: index,
            fieldId: 'taxbasis',
            value: item.amount,
        });

        document.setSublistValue({
            sublistId: 'taxdetails',
            line: index,
            fieldId: 'taxcode',
            value: item.taxCode,
        });
    }
});
Thank you in advance for your support.
Also, is it expected/normal practice that I have to save the document after adding the items, then load it again just to be able to populate the taxdetails sublist? This works, but feels more like a workaround.
g
Not super familiar with SuiteTax but enabled it in our sandbox to see if it would be a good for our use case. Ran across this when looking into some errors that were bubbling up with the change. Not positive if this is relevant but I needed to add/run this before save to get around the issues I was running into.
Copy code
var calculateTax = newRec.getMacro({ id: 'calculateTax' });
calculateTax();
Here is more info https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_N3191224.html#subsect_1565106608
n
i got an error after setCurrentSublistValue() {"type":"error.SuiteScriptError","name":"INVALID_FLD_VALUE","message":"You have entered an Invalid Field Value 23667 for the following field: taxcode","id":"","stack":["Error\n at RecordInvoker.setCurrentSublistValue (suitescript/resources/javascript/record/serverRecordService.js
m
You don't have to save, then reload to add tax details. In the
taxdetailsreference
field, you can use 'NEW1' for tax details referring to line 1 on the transaction, 'NEW2' for line 2 and so on... NetSuite will update that field with the actual ID on creation.
n
Copy code
if (isSuiteTaxEngine) {
    newDocument.setValue('taxdetailsoverride', true);
}

if (items.length > 0) {
    processItems(newDocument, items, 'item');
    processItemTaxes(newDocument, items, 'item');
}

// save new record
let newDocumentId = newDocument.save({
    ignoreMandatoryFields: false,
});

items.forEach((item, index) => {
    if (item.taxCode !== undefined && item.taxCode !== null) {
        const lineIndex = index + 1;
        if (isSuiteTaxEngine) {
            document.setSublistValue({
                sublistId: 'taxdetails',
                line: index,
                fieldId: 'taxdetailsreference',
                value: 'NEW' + lineIndex,
            });

            document.setSublistValue({
                sublistId: 'taxdetails',
                line: index,
                fieldId: 'taxcode',
                value: item.taxCode,
            });
            document.setSublistValue({
                sublistId: 'taxdetails',
                line: index,
                fieldId: 'taxamount',
                value: item.taxAmount,
            });
            document.setSublistValue({
                sublistId: 'taxdetails',
                line: index,
                fieldId: 'taxbasis',
                value: item.amount,
            });
            document.setSublistValue({
                sublistId: 'taxdetails',
                line: index,
                fieldId: 'taxrate',
                value: item.taxRate,
            });

            return;
        }
You have entered an Invalid Field Value 11448 for the following field: taxcode
@Mike Robbins help me please🫠
m
@netsuiteforstrongmen It doesn't look like you've set the
nexus
, or
taxtype
fields yet. Look at it in the UI. You'll need to set the fields in the same order.
nexus
filters down the available tax types, and
taxtype
filters down the available tax codes.