You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NetSuite ClientScript发票行项目变更时获取描述并设置日本子公司对应税码

NetSuite 日本子公司税率逻辑完善方案

核心修改说明

你需要修改日本子公司逻辑段的3处核心问题:

  • 原代码中description变量被赋值为空,没有读取当前行的描述字段值,使用NetSuite ClientScript提供的getCurrentSublistText方法即可获取当前正在编辑的item子表行的描述内容
  • 原代码if(inv_type[i] == 'Services');末尾多了分号,会导致条件判断失效,后续代码块会无条件执行,需要删除该分号
  • 原代码字符串包含判断使用的contains方法不是JS标准方法,存在兼容性问题,建议改用标准的includes方法,同时转小写匹配避免大小写导致的判断遗漏

修正后的日本子公司逻辑代码

//////////////////////Tax calculation for subsidiary 'Japan'
if(scriptContext.sublistId == 'item' && subsidiary_id == 6){
    var inv_type = objRecord.getText({fieldId:'custbody3'});
    for(var i=0;i<inv_type.length;i++){
        val = inv_type[i];
        log.debug({
            title: 'inv_type', 
            details: inv_type[i]
        });
        console.log('inv_type',inv_type);
        //inv_type = 'Service' || 'Subscription'
        if(inv_type[i] == 'Services'){
            // 获取当前行项目描述,兜底空字符串避免null报错
            var description = objRecord.getCurrentSublistText({
                sublistId: 'item',
                fieldId: 'description'
            }) || '';
            var lowerDesc = description.toLowerCase();
            //////If the Description contains Non JP set Tax Rate = 0
            if(lowerDesc.includes("non jp")){
                objRecord.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'taxcode',
                    value: 193,
                    ignoreFieldChange: true,
                    enableSourcing: true
                });
                // 按需补充对应税率设置
                objRecord.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'taxrate1',
                    value: 0,
                    ignoreFieldChange: true,
                    enableSourcing: true
                });
            }
            //////If the Description contains JP set Tax Rate = 10
            else if(lowerDesc.includes("jp")){
                // 按需替换为日本国内适用的taxcode ID
                objRecord.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'taxcode',
                    value: 【请替换为日本国内税率对应的taxcode ID】,
                    ignoreFieldChange: true,
                    enableSourcing: true
                });
                objRecord.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'taxrate1',
                    value: 7,
                    ignoreFieldChange: true,
                    enableSourcing: true
                });
            }
        }
    }
}
///////////////////////////////////End

额外注意事项

  • 如果你需要监听用户手动修改行描述的场景,需要新增fieldChanged事件处理函数,在描述字段修改时触发相同的税率设置逻辑,因为postSourcing仅在字段值被系统源数据联动更新时触发,手动修改不会触发该事件
  • 原代码中inv_type的多条件判断可以优化为数组匹配,大幅简化代码:比如把符合条件的inv_type值放到数组const validTypes = ['Services','Subscription','Expenses','Customer Summit Sponsor Fees'],然后用validTypes.includes(inv_type[i])即可完成判断,无需写冗长的或条件

内容的提问来源于stack exchange,提问作者NooB Gamer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 04:09:02