如何通过Restlet为NetSuite发票行项设置Tax Group?
NetSuite发票行项Tax Group配置问题
问题背景
我们正在开展外部系统与NetSuite的集成工作,外部系统存储发票详情,通过Restlet在NetSuite中创建发票摘要信息。目前已能正确配置发票表头及大部分行项信息,但无法为服务类行项设置Tax Group(注意:需设置的是Tax Group而非Tax Code)以应用对应销售税,手动操作可实现该配置。
当前使用的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 } } ] }
已尝试的变体方案
方案1:新增taxItem子列表行(报错)
抛出SSS_INVALID_SUBLIST_OPERATION错误:
"lines": [ { "type": "item", "lineValues": { "item": 623, "quantity": 1, "amount": 1000.00, "location": 2 } }, { "type": "taxItem", "lineValues": { "taxgroup": 199 } } ]
方案2:多种taxCode写法(无报错但未生效)
以下写法均无报错,但Tax Group未成功应用:
"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 } } ]
可行解决方案
在动态模式下设置Tax Group,核心是使用taxgroup字段而非taxCode指定Tax Group的内部ID,同时确保行项的isTaxable为true。
修改后的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, "isTaxable": true, "taxgroup": 199 } } ] }
代码适配(可选优化)
当前Restlet代码已支持动态设置子列表字段,若仍未生效,可针对taxgroup字段启用强制同步sourcing,确保NetSuite正确识别:
lineFields.forEach(function(lineField){ var thisValue = lineValues[lineField]; if (_isDateValue(thisValue)) { thisValue = _makeDateValue(thisValue) }; var options = { sublistId: lineType, fieldId: lineField, value: thisValue }; // 针对taxgroup字段启用强制同步sourcing if (lineField === 'taxgroup') { options.ignoreFieldChange = false; options.forceSyncSourcing = true; } newRecord.setCurrentSublistValue(options); });
调整后,NetSuite会正确关联指定的Tax Group并应用对应的销售税。
内容的提问来源于stack exchange,提问作者Cass
相关产品推荐
相关产品推荐

