我在设置与发票相关的行项目上存在一些问题,这是我要传递给RESTlet的一个发票项目的JSON:
{
"item": {
"items": [
{
"taxCode": "8",
"quantity": 1,
"item": "7",
"description": "description",
"amount": 2280.00
}
]
}
}SuiteScript解析JSON并在必要时设置字段,我能够设置所有其他类型的字段,除了税务代码外,我还尝试将Id作为字符串和整数传递,并将其作为对象传递,如下面的两个示例所示,但无论我做什么,我都会继续获取错误。
"taxcode": {
"items": [
{ "id" : 8 }
]
}
"taxcode": {
{ "id" : 8 }
}这是我的RESTlet SuiteScript,它遍历项目并设置相关的字段值,正如上面提到的;它适用于所有其他字段,这只是我遇到问题的税法
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()
});
}有什么想法吗?
发布于 2022-05-06 13:32:02
史上最糟糕的API!
你必须设置最后一个TaxCode ..。或者是其他的东西把它擦掉了-_-
不管用:
{
"item": {
"items": [
{
"taxCode": "8",
"quantity": 1,
"item": "7",
"description": "description",
"amount": 2280.00
}
]
}
}工作非常好:
{
"item": {
"items": [
{
"quantity": 1,
"item": "7",
"description": "description",
"amount": 2280.00,
"taxCode": "8"
}
]
}
}https://stackoverflow.com/questions/72139645
复制相似问题