-2
function CheckDates() {
 var ExtendToDate = GetFieldValue("Extend to Date");
 var LastLeaverDate = GetFieldValue("ARP Mandatory Exit Date");



     var difference = moment.duration(moment(LastLeaverDate, 'MM-DD-YYYY') - 
moment(ExtendToDate, 'MM-DD-YYYY')).asDays();

 if(difference < 30) {
      alert("This persons will have to leave within 30 days of the proposed extension");
 }

}

function CheckDates_WithDelay() { 
// Delay 1000 milliseconds before starting CheckDates
setTimeout("CheckDates()",1500);

}

AddChangeCallback("ARP_MANDATORY_EXIT_DATE", CheckDates_WithDelay);
AddChangeCallback("EXTEND_TO_DATE", CheckDates_WithDelay);

在表单上,​​用户可以更改扩展至日期和 ARP 退出日期。这就是为什么我添加了更改回调和延迟。我已经测试了很多次,但我没有收到任何警报...

感谢你的帮助。

4

2 回答 2

1

我不知道AddChangeCallback()它是什么,为什么它从"Extend to Date"to改变"EXTEND_TO_DATE",我也不明白为什么超时,但我认为它应该看起来像这样,假设消息应该出现在 ExtendToDateLastLeaverDate 之后,但不到 30 天之后.

此解决方案使用http://momentjs.com/(因此您不必担心[奇怪的事情][1])

// Observe inputs for a change (I assume)
AddChangeCallback("ARP_MANDATORY_EXIT_DATE", CheckDates);
AddChangeCallback("EXTEND_TO_DATE", CheckDates);

// This will display an alert if ExtendToDate is in the period
// 30 days after LastLeaverDate
function CheckDates() {
     // Get the field values
     var ExtendToDate = GetFieldValue("EXTEND_TO_DATE");
     var LastLeaverDate = GetFieldValue("LAST_LEAVER_DATE");

     // Check if values are present
     if(ExtendToDate.length === 0 || LastLeaverDate === 0) {
          // at least one of the fields is empty -> leave the function
          return false;
     }

     // convert both dates to moment.js-objects [http://momentjs.com/docs/#/parsing/] and check if they're parsable
     var ExtendToDateMoment = moment(ExtendToDate, 'MM-DD-YY');
     if(ExtendToDateMoment.isValid() === false)  {
         return false;
     }

     var LastLeaverDateMoment = moment(LastLeaverDate, 'MM-DD-YY');
     if(LastLeaverDateMoment.isValid() === false)  {
         return false;
     }

     /*
     - subtract them,
     - create a moment.duration-object [http://momentjs.com/docs/#/durations/] and
     - return the difference in days [http://momentjs.com/docs/#/durations/days/]
     */
     var difference = moment.duration(ExtendToDateMoment - LastLeaverDateMoment).asDays();

     // compare the difference to a fixed value
     if(difference < 30) {
          alert("This persons will have to leave within 30 days of the proposed extension");
     }
}
于 2015-09-02T11:43:37.657 回答
0
var mS = 1000 * 60 * 60 * 24;

function CheckDates() {

    var a = GetFieldValue("ARP_MANDATORY_EXIT_DATE") ;
    var lastLeaverDate = (Date.parse(a));

    var b = GetFieldValue("EXTEND_TO_DATE");
    var extendToDate = (Date.parse(b));

    var differenceCalc = (lastLeaverDate - extendToDate);

    var difference = (differenceCalc / mS);

    if(difference < 30) {
          alert("This persons will have to leave within 30 days of the proposed extension");
     }
}
于 2015-09-15T10:32:50.350 回答