问题
I have created a script to add a Finance Charge item to my sales orders when they are edited but can't get it to set the tax Code. Also the line is not committing (because of the tax code issue?)
I have tried Internal IDs and names but am stuck
Any help?
define(['N/currentRecord'],
function(currentRecord) {
function AddFinanceCharge() {
try {
var record = currentRecord.get();
record.selectNewLine({ //add a line to a sublist
sublistId: 'item' //specify which sublist
});
record.setCurrentSublistValue({ //set item field
sublistId: 'item',
fieldId: 'item',
value: 1003 //replace with item internal id
});
record.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: 1 //replace with quantity
});
record.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxCode',
value: 'VAT:S-GB'
});
record.commitLine({ //writes the line entry into the loaded record
sublistId: 'item'
});
log.debug ({
title: 'Success',
details: 'Alert displayed successfully'
});
} catch (e) {
log.error ({
title: e.name,
details: e.message
});
}
}
return {
pageInit: AddFinanceCharge
};
});
回答1:
If you only use Tax codes, not Tax Groups I believe you can create a search to find internal ids:
var taxitemSearchObj = search.create({
type: "salestaxitem",
columns: ["internalid", "country", "rate"],
filters: [['firstFilter', 'firstComparisonOperator', firstValue]], 'and', ['anotherFilter', 'anotherComparisonOperator', anotherValue]] // i.e. ['itemid', 'is' 'VAT:S-GB'],
});
You can find available search filters in the NS record browser- here (2019.2 version)
'VAT:S-GB' might be itemid? Then:
var taxCodeInternalId = taxitemSearchObj.run().getRange(0,1)[0].id // If you know there is only 1 code matching the search query
record.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode', // FYI I'm not sure if capitalization matters here but I downcased the capital C
value: taxCodeInternalId
});
**Disclaimer - Does NOT work with mixed tax code / tax groups. To get that you'll need to make the search dynamic ('taxgroup' or 'salestaxitem'). Unfortunately Netsuite will overwrite your taxcode internal ID if "ENABLE TAX LOOKUP ON SALES AND PURCHASES" is selected in your tax preferences (Setup > Accounting > Tax Setup - set per nexus). If this option is not selected you'll need to make sure to set a tax code on every line item.
回答2:
you have to pass internal id of the tax code if you re using setValue, use SetText instead of setValue and check.
来源:https://stackoverflow.com/questions/53714852/setting-the-tax-code-on-a-sales-order-item-in-suitescript-2-0