首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在SuiteScript 2.1中设置发票税号

如何在SuiteScript 2.1中设置发票税号
EN

Stack Overflow用户
提问于 2022-05-06 10:00:54
回答 1查看 271关注 0票数 0

我在设置与发票相关的行项目上存在一些问题,这是我要传递给RESTlet的一个发票项目的JSON:

代码语言:javascript
复制
    {
        "item": {
            "items": [
                {
                    "taxCode": "8",
                    "quantity": 1,
                    "item": "7",
                    "description": "description",
                    "amount": 2280.00
                }
            ]
        }
    }

SuiteScript解析JSON并在必要时设置字段,我能够设置所有其他类型的字段,除了税务代码外,我还尝试将Id作为字符串和整数传递,并将其作为对象传递,如下面的两个示例所示,但无论我做什么,我都会继续获取错误。

代码语言:javascript
复制
"taxcode": {
    "items": [
        { "id" : 8 }
    ]
}
"taxcode": {
    { "id" : 8 }
}

这是我的RESTlet SuiteScript,它遍历项目并设置相关的字段值,正如上面提到的;它适用于所有其他字段,这只是我遇到问题的税法

代码语言:javascript
复制
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()
    });
}

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-06 13:32:02

史上最糟糕的API!

你必须设置最后一个TaxCode ..。或者是其他的东西把它擦掉了-_-

不管用:

代码语言:javascript
复制
{
    "item": {
        "items": [
            {
                "taxCode": "8",
                "quantity": 1,
                "item": "7",
                "description": "description",
                "amount": 2280.00
            }
        ]
    }
}

工作非常好:

代码语言:javascript
复制
{
    "item": {
        "items": [
            {
                "quantity": 1,
                "item": "7",
                "description": "description",
                "amount": 2280.00,
                "taxCode": "8"
            }
        ]
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72139645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档