如何限制用户在 NetSuite 自定义日期字段中输入未来日期?

时间:2021-04-08 13:05:39

标签: netsuite suitescript

是否可以限制用户在 netsuite 字段中输入未来日期?

用例: 限制用户在收货日期中添加未来日期。此字段应该是今天或任何过去的日期,但不是未来。

如果有人有想法,请回复。

1 个答案:

答案 0 :(得分:2)

以下两种方法都适用于客户端脚本。

这定义了在用户或客户端调用更改字段时执行的验证函数。

  function validateField(context) {
    var curRec = context.currentRecord;
    var fieldName = context.fieldId;
    if (fieldName === 'date') { //replace "date" with your field id
      var recDate = curRec.getValue({fieldId: fieldName});
      var today = new Date();
      if (recDate > today){
        alert('You cannot enter a future date');
        curRec.setValue({
          fieldId: 'date',
          value: null
        });
      }
      return true;
    }

这定义了在用户或客户端调用更改字段时执行的函数。

  function fieldChanged(context) {
    var curRec = context.currentRecord;
    var fieldName = context.fieldId;
    if (fieldName === 'date'){ //replace "date" with your field id
      var recDate = curRec.getValue({fieldId: fieldName});
      var today = new Date();
      if (recDate > today){
        alert('You cannot enter a future date');
        curRec.setValue({
          fieldId: 'date',
          value: null
        });
    }