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

如何限制用户在NetSuite自定义日期字段中输入未来日期?,netsuite,suitescript,Netsuite,Suitescript,是否可以限制用户在netsuite字段中输入未来日期 用户案例: 限制用户在装运接收日期中添加未来日期。此字段应为今天或任何过去日期,但不能为将来日期 如果有人有想法,请回复。以下两项都可以在客户端脚本中使用 这定义了当用户或客户端调用更改字段时执行的验证函数 function validateField(context) { var curRec = context.currentRecord; var fieldName = context.fieldId; if

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

用户案例: 限制用户在装运接收日期中添加未来日期。此字段应为今天或任何过去日期,但不能为将来日期


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

以下两项都可以在客户端脚本中使用

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

  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
        });
    }
这定义了当用户或客户端调用更改字段时执行的函数

  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
        });
    }

记录上的客户端脚本可用于执行验证。以SuiteScript 2.x为例,您可以使用
validateField
中的代码拒绝超过当前日期的字段值。附议上述答案^