I'm having some issues with setting the Tax Code on a Line Item related to an Invoice, this is the JSON for 1 of the Invoice Items I am passing to a RESTlet:
{
"item": {
"items": [
{
"taxCode": "8",
"quantity": 1,
"item": "7",
"description": "description",
"amount": 2280.00
}
]
}
}
The SuiteScript parses the JSON and sets the fields where necessary, I am able to set every other type of field, apart from the tax code, I have tried passing the Id as String and an Integer, as well as passing it as an object, like the below 2 examples, but I keep on getting errors no matter what I do.
"taxcode": {
"items": [
{ "id" : 8 }
]
}
"taxcode": {
{ "id" : 8 }
}
This is my RESTlet SuiteScript that iterates over the items and sets the relevant field values, as mentioned above; this is working for all other fields, it's just the tax code I am having issues with
for (let i of req[cust][key].items) {
// Select the sublist line
invoice.selectNewLine({
sublistId: key.toLowerCase()
});
// Iterate over the fields
for (let j in i) {
try {
// If the current field is an object
if (i[j] instanceof Object) {
// Get the subrecord
var child = invoice.getCurrentSublistSubrecord({
sublistId: key.toLowerCase(),
fieldId: j.toLowerCase()
});
// Set it's fields field
for (let k in i[j]) {
// Set the field and value
child.setValue({
fieldId: k.toLowerCase(),
value: i[j][k]
});
}
// Commit the line
invoice.setValue({
fieldId: j.toLowerCase(),
value: child
});
} else {
log.debug(
"setCurrentSublistValue",
JSON.stringify({
sublistId: key.toLowerCase(),
fieldId: j.toLowerCase(),
value: i[j]
})
);
// Set the fields
invoice.setCurrentSublistValue({
sublistId: key.toLowerCase(),
fieldId: j.toLowerCase(),
value: i[j]
});
}
} catch (e) {
log.debug(127, j);
log.debug(128, e);
}
}
// Commit the line
invoice.commitLine({
sublistId: key.toLowerCase()
});
}
Any ideas?
WORST API EVER!
You have to set the TaxCode last... or something else that is being set wipes it out -_-
Doesn't work:
{
"item": {
"items": [
{
"taxCode": "8",
"quantity": 1,
"item": "7",
"description": "description",
"amount": 2280.00
}
]
}
}
Works perfectly fine:
{
"item": {
"items": [
{
"quantity": 1,
"item": "7",
"description": "description",
"amount": 2280.00,
"taxCode": "8"
}
]
}
}