NetSuite 在更改 "Line Items" 期间获取描述和设置税
NetSuite Get Description and Set Tax during Onchange "Line Items"
我正在学习 NetSuite,
我正在尝试存档的场景,
在发票中,添加行项目时,如果项目描述包含“非日本”,则添加税值“193”,否则其他税。
我的问题:
如何在用户 select 或更改描述时获取行项目的描述。
我正在尝试执行自定义功能:
该函数将在以下时间执行:“POST SOURCING FUNCTION”
我的代码
if(scriptContext.sublistId == 'item' && subsidiary_id == 6){
var inv_type = objRecord.getText({fieldId:'custbody3'});
var inv_val;
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');
{
var description="";
//////If the Description contains Non JP set Tax Rate = 0
if(description.contains("non JP"))
{
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 193,
ignoreFieldChange: true,
enableSourcing: true
});
}
//////If the Description contains Non JP set Tax Rate = 10
if(description.contains("JP"))
{
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 7,
ignoreFieldChange: true,
enableSourcing: true
});
}
}
}
}
我的完整脚本代码
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/log'],
/**
* @param {record} record
*/
function (record, log) {
/**
* Defines the function that is executed after a sublist is inserted, removed, or edited.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId -
* @since 2015.2
*/
function postSourcing(scriptContext) {
try {
var objRecord = scriptContext.currentRecord;
var subsidiary_id = objRecord.getValue({fieldId:'subsidiary'});
//Tax Calculation for China Subsidiary
if(scriptContext.sublistId == 'item' && subsidiary_id == 5){
var inv_type = objRecord.getText({fieldId:'custbody3'});
var inv_val;
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' || inv_type[i] == 'Subscription' || (inv_type[i] == 'Subscription' && (inv_type[i] =='Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' && (inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees') || (inv_type[i] == 'Services' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees' && inv_type[i] == 'Subscription' ) || (inv_type[i] == 'Subscription' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees')){
log.debug({title: 'inv_type1', details: inv_type[i]});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 52,
ignoreFieldChange: true,
enableSourcing: true
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 6,
ignoreFieldChange: true,
enableSourcing: true
});
// objRecord.commitLine('item');
}
if(inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees') {
log.debug({title: 'inv_type1', details: inv_type[i]});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 51,
ignoreFieldChange: true,
enableSourcing: true
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 0,
ignoreFieldChange: true,
enableSourcing: true
});
// objRecord.commitLine('item');
}
}
}
//Tax Calculation for Singapore Subsidiary
if(scriptContext.sublistId == 'item' && subsidiary_id == 69){
var inv_type = objRecord.getText({fieldId:'custbody3'});
var inv_val;
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' || (inv_type[i] == 'Subscription' && (inv_type[i] =='Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' && (inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees') || (inv_type[i] == 'Services' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees' && inv_type[i] == 'Subscription' ) || (inv_type[i] == 'Subscription' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees')){
log.debug({title: 'inv_type1', details: inv_type[i]});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 193,
ignoreFieldChange: true,
enableSourcing: true
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 7,
ignoreFieldChange: true,
enableSourcing: true
});
// objRecord.commitLine('item');
}
if(inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees' || inv_type[i] == 'Subscription' ) {
log.debug({title: 'inv_type1', details: inv_type[i]});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 192,
ignoreFieldChange: true,
enableSourcing: true
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 0,
ignoreFieldChange: true,
enableSourcing: true
});
// objRecord.commitLine('item');
}
}
}
//////////////////////Tax calculation for subsidiary 'Japan'
if(scriptContext.sublistId == 'item' && subsidiary_id == 6){
var inv_type = objRecord.getText({fieldId:'custbody3'});
var inv_val;
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');
{
var description="";
//////If the Description contains Non JP set Tax Rate = 0
if(description.contains("non JP"))
{
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 193,
ignoreFieldChange: true,
enableSourcing: true
});
}
//////If the Description contains Non JP set Tax Rate = 10
if(description.contains("JP"))
{
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 7,
ignoreFieldChange: true,
enableSourcing: true
});
}
}
}
}
/////////////////////////////////////End
return true;
} catch (e) {
console.log("Error in validateLine : " + e);
log.error('Error in validateLine', e);
}
}
return {
postSourcing: postSourcing
};
});
其他功能正常,
我只需要获取日本部分(已添加到评论中)的行项目的描述,并根据描述设置税费。
创建一个自定义列字段和来源,当项目被 select 编辑时,所以当您 select 项目描述将自动填充。在你的脚本中使用它来验证你的逻辑
我正在学习 NetSuite,
我正在尝试存档的场景, 在发票中,添加行项目时,如果项目描述包含“非日本”,则添加税值“193”,否则其他税。
我的问题:
如何在用户 select 或更改描述时获取行项目的描述。
我正在尝试执行自定义功能:
该函数将在以下时间执行:“POST SOURCING FUNCTION”
我的代码
if(scriptContext.sublistId == 'item' && subsidiary_id == 6){
var inv_type = objRecord.getText({fieldId:'custbody3'});
var inv_val;
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');
{
var description="";
//////If the Description contains Non JP set Tax Rate = 0
if(description.contains("non JP"))
{
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 193,
ignoreFieldChange: true,
enableSourcing: true
});
}
//////If the Description contains Non JP set Tax Rate = 10
if(description.contains("JP"))
{
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 7,
ignoreFieldChange: true,
enableSourcing: true
});
}
}
}
}
我的完整脚本代码
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/log'],
/**
* @param {record} record
*/
function (record, log) {
/**
* Defines the function that is executed after a sublist is inserted, removed, or edited.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId -
* @since 2015.2
*/
function postSourcing(scriptContext) {
try {
var objRecord = scriptContext.currentRecord;
var subsidiary_id = objRecord.getValue({fieldId:'subsidiary'});
//Tax Calculation for China Subsidiary
if(scriptContext.sublistId == 'item' && subsidiary_id == 5){
var inv_type = objRecord.getText({fieldId:'custbody3'});
var inv_val;
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' || inv_type[i] == 'Subscription' || (inv_type[i] == 'Subscription' && (inv_type[i] =='Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' && (inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees') || (inv_type[i] == 'Services' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees' && inv_type[i] == 'Subscription' ) || (inv_type[i] == 'Subscription' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees')){
log.debug({title: 'inv_type1', details: inv_type[i]});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 52,
ignoreFieldChange: true,
enableSourcing: true
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 6,
ignoreFieldChange: true,
enableSourcing: true
});
// objRecord.commitLine('item');
}
if(inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees') {
log.debug({title: 'inv_type1', details: inv_type[i]});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 51,
ignoreFieldChange: true,
enableSourcing: true
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 0,
ignoreFieldChange: true,
enableSourcing: true
});
// objRecord.commitLine('item');
}
}
}
//Tax Calculation for Singapore Subsidiary
if(scriptContext.sublistId == 'item' && subsidiary_id == 69){
var inv_type = objRecord.getText({fieldId:'custbody3'});
var inv_val;
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' || (inv_type[i] == 'Subscription' && (inv_type[i] =='Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' && (inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees')) || (inv_type[i] == 'Services' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees') || (inv_type[i] == 'Services' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees' && inv_type[i] == 'Subscription' ) || (inv_type[i] == 'Subscription' && inv_type[i] == 'Expenses' && inv_type[i] == 'Customer Summit Sponsor Fees')){
log.debug({title: 'inv_type1', details: inv_type[i]});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 193,
ignoreFieldChange: true,
enableSourcing: true
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 7,
ignoreFieldChange: true,
enableSourcing: true
});
// objRecord.commitLine('item');
}
if(inv_type[i] == 'Expenses' || inv_type[i] == 'Customer Summit Sponsor Fees' || inv_type[i] == 'Subscription' ) {
log.debug({title: 'inv_type1', details: inv_type[i]});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 192,
ignoreFieldChange: true,
enableSourcing: true
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 0,
ignoreFieldChange: true,
enableSourcing: true
});
// objRecord.commitLine('item');
}
}
}
//////////////////////Tax calculation for subsidiary 'Japan'
if(scriptContext.sublistId == 'item' && subsidiary_id == 6){
var inv_type = objRecord.getText({fieldId:'custbody3'});
var inv_val;
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');
{
var description="";
//////If the Description contains Non JP set Tax Rate = 0
if(description.contains("non JP"))
{
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: 193,
ignoreFieldChange: true,
enableSourcing: true
});
}
//////If the Description contains Non JP set Tax Rate = 10
if(description.contains("JP"))
{
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxrate1',
value: 7,
ignoreFieldChange: true,
enableSourcing: true
});
}
}
}
}
/////////////////////////////////////End
return true;
} catch (e) {
console.log("Error in validateLine : " + e);
log.error('Error in validateLine', e);
}
}
return {
postSourcing: postSourcing
};
});
其他功能正常,
我只需要获取日本部分(已添加到评论中)的行项目的描述,并根据描述设置税费。
创建一个自定义列字段和来源,当项目被 select 编辑时,所以当您 select 项目描述将自动填充。在你的脚本中使用它来验证你的逻辑