致力于与外部系统的集成。外部系统保存发票的详细信息。我们使用 Restlet 在 Netsuite 中创建包含摘要信息的发票。
服务发票中添加了一项。有谁知道如何编写 Restlet 代码以将税收组应用于该项目?
我在 Netsuite 中正确应用了标头和大部分行项目信息,但似乎无法访问税收组,以便应用适当的销售税。可以手动做。注意:重要的是税务组,而不是税码!请参阅下面尝试的变体。
RESTLET代码:
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
};
}
RESTLET 调用的 JSON:
{
"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
}
}
]
}
尝试了这些变化
这会引发“SSS_INVALID_SUBLIST_OPERATION”错误
"lines": [
{
"type": "item",
"lineValues": {
"item": 623,
"quantity": 1,
"amount": 1000.00,
"location": 2
}
},
{
"type": "taxItem",
"lineValues": {
"taxgroup": 199
}
}
]
没有错误,但没有对以下所有项目应用税组
"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
}
}
]
通过反复试验,所需的组合是提供taxcode内部id值和taxcode_display文本值。不得引用 isTaxable 字段。