在SuiteScript 2.0中为销售订单项目设置税码

问题描述 投票:1回答:2

我已经创建了一个脚本,用于在编辑销售订单时将财务费用项目添加到我的销售订单中,但是无法通过它来设置税码。此外,该行未提交(由于税码问题?)

我尝试过使用内部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
2个回答
0
投票

如果您正在使用setValue,则必须传递税码的内部ID,使用SetText而不是setValue并进行检查。


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记录浏览器中找到可用的搜索过滤器-here (2019.2 version)

'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
    });

**免责声明-不适用于混合税代码/税组(甚至不能确定它是否适用于just税收组),但似乎适用于税代码。如果任何人[[does知道如何使用混合税,请告诉我!

© www.soinside.com 2019 - 2024. All rights reserved.