首页 > 解决方案 > 在 SuiteScript 2.0 中设置销售订单项目的税码

问题描述

我创建了一个脚本,以便在编辑销售订单时将财务费用项目添加到我的销售订单中,但无法使用它来设置税码。该行也没有提交(因为税法问题?)

我已经尝试过内部 ID 和名称,但被卡住了

有什么帮助吗?

define(['N/currentRecord'],

    function(currentRecord) {

        function AddFinanceCharge() {

            try {
           
            var record = currentRecord.get();
            

		record.selectNewLine({ //add a line to a sublist
		    sublistId: 'item'      //specify which sublist
		});

		record.setCurrentSublistValue({   //set item field
		    sublistId: 'item',
		    fieldId: 'item',
		    value: 1003  //replace with item internal id 
		});
		record.setCurrentSublistValue({
		    sublistId: 'item',
		    fieldId: 'quantity',
		    value: 1 //replace with quantity
		});
        record.setCurrentSublistValue({
          	sublistId: 'item',
          	fieldId: 'taxCode',
          	value: 'VAT:S-GB'
        });

		record.commitLine({  //writes the line entry into the loaded record
		    sublistId: 'item'
		});


                log.debug ({
                    title: 'Success',
                    details: 'Alert displayed successfully'
                });
        
            } catch (e) {
           
                log.error ({ 
                    title: e.name,
                    details: e.message
                });           
            } 
        }
              
    return {
        pageInit: AddFinanceCharge
    };
});
 

标签: suitescript2.0

解决方案


如果您只使用税码,而不是税组,我相信您可以创建一个搜索来查找内部 ID:

var taxitemSearchObj = search.create({
    type: "salestaxitem",
    columns: ["internalid", "country", "rate"],
    filters: [['firstFilter', 'firstComparisonOperator', firstValue]], 'and', ['anotherFilter', 'anotherComparisonOperator', anotherValue]] // i.e. ['itemid', 'is' 'VAT:S-GB'], 
  });

您可以在 NS 记录浏览器中找到可用的搜索过滤器 - 此处(2019.2 版)

'VAT:S-GB' 可能是 itemid?然后:

var taxCodeInternalId = taxitemSearchObj.run().getRange(0,1)[0].id // If you know there is only 1 code matching the search query
record.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'taxcode', // FYI I'm not sure if capitalization matters here but I downcased the capital C
        value: taxCodeInternalId
    });

**免责声明 - 不适用于混合税法/税组。为此,您需要使搜索动态化(“taxgroup”或“salestaxitem”)。不幸的是,如果在您的税务偏好(设置 > 会计 > 税务设置 - 根据关联设置)中选择了“启用对销售和采购的税务查询”,Netsuite 将覆盖您的税务代码内部 ID。如果选择此选项,您需要确保为每个行项目设置税码。


推荐阅读