LineItem 上的 Netsuite 字段更改功能触发 2 次

Netsuite Field change function on LineItem is triggering 2 times

我正在尝试归档以下内容

如果行项目“custcol_celigo_sfnc_line_id”字段匹配值“01t0g00000bx4WDAAY”,则添加日期。

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

/**
 *@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次,所以加倍。如何让它触发一次?

提前致谢

我认为脚本不会触发两次。 您收到两次“已触发”警报吗?

/**
 *@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;
});

试试上面的代码一次。在下面的评论中让我知道更新。