【问题标题】:Netsuite Field change function on LineItem is triggering 2 timesLineItem 上的 Netsuite 字段更改功能正在触发 2 次
【发布时间】:2021-09-22 14:45:10
【问题描述】:

我正在尝试归档以下内容

如果 lineitem,"custcol_celigo_sfnc_line_id" 字段与值 "01t0g00000bx4WDAAY" 匹配,则添加日期。

我遇到了这个问题,这条记录触发了 2 次而不是 1 次。

/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */
define(['N/record', 'N/search', 'N/url', 'N/https', 'N/runtime'], function(record, search, url, https, runtime) {

    function fieldChanged(context) {
    
        var currentRecord = context.currentRecord;
  
   
            var sublistName = context.sublistId;
            var sublistFieldName = context.fieldId;
   //  alert(JSON.stringify(currentRecord));
        //alert(JSON.stringify(context));
            var line = context.line;
      var start_Date="custcol_atlas_contract_start_date";
      var end_date="custcol_atlas_contract_end_date";
       if (sublistName === 'item') {
        if (sublistFieldName === 'custcol_celigo_sfnc_line_id')
        {
              var value = currentRecord.getCurrentSublistValue({
                            sublistId: sublistName,
                            fieldId: sublistFieldName
                        })
if(value!="01t0g00000bx4WDAAY"||value!="01t70000004b5TWAAY"||value!="01t70000004b6LZAAY"||value!="01t0g00000Z9ryHAAR"||value!="01t0g00000Z9ryCAAR"||value!="01t0g00000aYySFAA0"||value!="01t0g00000aZJyRAAW")
  {
       
                if(value=="01t0g00000bx4WDAAY")
                  {
                  //  alert("Triggered");
                         var stdate = currentRecord.getCurrentSublistValue({
                            sublistId: sublistName,
                            fieldId: start_Date
                        })
                         
                         var newDate = new Date(stdate.setMonth(stdate.getMonth()+1));
                   
                            currentRecord.setCurrentSublistValue({
                            sublistId: sublistName,
                            fieldId: start_Date,
                            value: newDate
                        });
                  }
            
           
            
            
  
        }
              
        }
       }
            return true;
    }
    var exports = {};


    exports.fieldChanged = fieldChanged;

    return exports;
});


这个脚本触发了 2 次,所以它加倍。如何让它触发一次?

提前致谢

【问题讨论】:

  • 你能提供输出吗
  • 输出是在日期字段上添加 1 个月。由于 fieldchange 触发了两次,它增加了 2 个月,例如:如果日期是 4/5/2015,预期输出:5/5/2015 但它增加了 6/5/2015
  • 我猜 getMonth()+1 是导致问题的原因。尝试不 +1 一次
  • 您确定您粘贴的脚本实际上正在触发吗?我看不出它怎么可能,因为您正在检查 value!="01t0g00000bx4WDAAY" 然后在 if 块内,您正在检查 value=="01t0g00000bx4WDAAY";永远不会是这样的

标签: javascript netsuite suitescript


【解决方案1】:

我不认为脚本可以触发两次。 您是否收到两次“已触发”警报?

/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */
define(['N/record', 'N/search', 'N/url', 'N/https', 'N/runtime'], function(record, search, url, https, runtime) {

    function fieldChanged(context) {
    
        var currentRecord = context.currentRecord;
  
   
            var sublistName = context.sublistId;
            var sublistFieldName = context.fieldId;
   //  alert(JSON.stringify(currentRecord));
        //alert(JSON.stringify(context));
            var line = context.line;
      var start_Date="custcol_atlas_contract_start_date";
      var end_date="custcol_atlas_contract_end_date";
       if (sublistName === 'item') {
        if (sublistFieldName === 'custcol_celigo_sfnc_line_id')
        {
              var value = currentRecord.getCurrentSublistValue({
                            sublistId: sublistName,
                            fieldId: sublistFieldName
                        })
if(value!="01t0g00000bx4WDAAY"||value!="01t70000004b5TWAAY"||value!="01t70000004b6LZAAY"||value!="01t0g00000Z9ryHAAR"||value!="01t0g00000Z9ryCAAR"||value!="01t0g00000aYySFAA0"||value!="01t0g00000aZJyRAAW")
  {
       
                if(value=="01t0g00000bx4WDAAY")
                  {
                  //  alert("Triggered");
                         var stdate = currentRecord.getCurrentSublistValue({
                            sublistId: sublistName,
                            fieldId: start_Date
                        })
                         
                         var newDate = new Date(stdate.setMonth(stdate.getMonth()));
                   
                            currentRecord.setCurrentSublistValue({
                            sublistId: sublistName,
                            fieldId: start_Date,
                            value: newDate
                        });
                  }
            
           
            
            
  
        }
              
        }
       }
            return true;
    }
    var exports = {};


    exports.fieldChanged = fieldChanged;

    return exports;
});

尝试上述代码一次。让我知道下面 cmets 中的更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 2020-01-09
    • 2019-02-02
    • 1970-01-01
    • 2019-04-03
    • 1970-01-01
    相关资源
    最近更新 更多