Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Date Comparison in Archer 6.3

UmaKrisVenkat
Contributor II

We have this Date Comparison JavaScript in Archer 5.5 running, but we are unable to get this script to work in Archer 6.3 P4.

I am attaching the copy of the current JavaScript that is being used and is working in Archer 5.5.

 

Please help us resolve this issue! 

14 REPLIES 14

Ilya_Khen
Champion III

Try this:

<script type="text/javascript">
var startDate = 46598, startDateValue;
var endDate = 46599, endDateValue;
var messageBoxText = "Please select a valid end date. End date cannot be before Start date";
var messageBoxTitle = 'Warning';
var daysToCompare = -1;
var oldApplyClick, oldSaveClick

Sys.Application.add_load(function() {
// Hijack Save/Apply Buttons
$('#master_btnSave').removeAttr('onclick').click(function() { DateCheck('save'); return false; });
$('#master_btnApply').removeAttr('onclick').click(function() { DateCheck('apply'); return false; });
});

function DateCheck(type) {
//Get Date Values
startDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(startDate, false)));
endDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(endDate, false)));
if(startDateValue && endDateValue) {
if(daydiff(parseDate(startDateValue), parseDate(endDateValue)) <= daysToCompare) {
WarningAlert(messageBoxText,'',messageBoxTitle);
} else {
SaveApply(type)
}
} else {
SaveApply(type)
}
}

function SaveApply(action) {
if(action == 'save') {
ShowAnimationAndPostback('master$btnSave');
} else if(action == 'apply') {
ShowAnimationAndPostback('master$btnApply');
}
}

function parseDate(str) {
str = str.getMonth()+1 + '/' + str.getDate() + '/' + str.getYear();
var mdy = str.split('/')
return new Date(mdy[2], mdy[0]-1, mdy[1]);
}

function daydiff(first, second) {
return (second-first)/(1000*60*60*24)
}
</script>

DavidPetty
Archer Employee
Archer Employee

The Save button acts a little differently in 6.3 and the Apply button no longer exists.

 

Below is the update code for 6.2

<script type="text/javascript">
     var startDate = 46598, startDateValue;
     var endDate = 46599, endDateValue;
     var messageBoxText = "Please select a valid end date. End date cannot be before Start date";
     var messageBoxTitle = 'Warning';
     var daysToCompare = -1;
     var oldApplyClick, oldSaveClick

     Sys.Application.add_load(function() {
          // Hijack Save Button
          $('#master_btnSave').clone().attr('id', 'master_customBtnSave').insertBefore('#master_btnSave');
          $('#master_btnSave').hide();
          $('#master_customBtnSave').unbind('click').prop("onclick", null).click(function(){ DateCheck('save');return false;});
     });

     function DateCheck(type) {
          //Get Date Values
          startDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(startDate, false)));
           endDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(endDate, false)));
           if(startDateValue && endDateValue) {
                if(daydiff(parseDate(startDateValue), parseDate(endDateValue)) <= daysToCompare) {
                     WarningAlert(messageBoxText,'',messageBoxTitle);
               } else {
                    SaveApply(type)
               }
           } else {
                SaveApply(type)
           }
     }

     function SaveApply(action) {
          if (action == 'save') {
               $('#master_btnSave').click();
           }
      }

     function parseDate(str) {
          str = str.getMonth()+1 + '/' + str.getDate() + '/' + str.getYear();
          var mdy = str.split('/')
          return new Date(mdy[2], mdy[0]-1, mdy[1]);
     }

     function daydiff(first, second) {
          return (second-first)/(1000*60*60*24)
     }
</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

And here's for 6.3 with Save And Close button.

<script type="text/javascript">
     var startDate = 46598, startDateValue;
     var endDate = 46599, endDateValue;
     var messageBoxText = "Please select a valid end date. End date cannot be before Start date";
     var messageBoxTitle = 'Warning';
     var daysToCompare = -1;
     var oldApplyClick, oldSaveClick

     Sys.Application.add_load(function() {
          // Hijack Save and Close Button
          $('#master_btnSave').clone().attr('id', 'master_customBtnSave').insertBefore('#master_btnApply');
          $('#master_btnSave').hide();
          $('#master_customBtnSave').unbind('click').prop("onclick", null).click(function(){ DateCheck('save');return false;});

          // Hijack Save Button
           $('#master_btnApply').clone().attr('id', 'master_customBtnApply').insertBefore('#master_btnApply');
           $('#master_btnApply').hide();
           $('#master_customBtnApply').unbind('click').prop("onclick", null).click(function(){ DateCheck('apply');return false;});
     });

     function DateCheck(type) {
          //Get Date Values
          startDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(startDate, false)));
          endDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(endDate, false)));
          if(startDateValue && endDateValue) {
               if(daydiff(parseDate(startDateValue), parseDate(endDateValue)) <= daysToCompare) {
                    WarningAlert(messageBoxText,'',messageBoxTitle);
               } else {
                    SaveApply(type)
               }
          } else {
                SaveApply(type)
          }
     }

     function SaveApply(action) {
          if (action == 'save') {
               $('#master_btnSave').click();
          } else if (action == 'apply') {
               $('#master_btnApply').click();
          }
     }

     function parseDate(str) {
          str = str.getMonth()+1 + '/' + str.getDate() + '/' + str.getYear();
          var mdy = str.split('/')
          return new Date(mdy[2], mdy[0]-1, mdy[1]);
     }

     function daydiff(first, second) {
          return (second-first)/(1000*60*60*24)
     }
</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 Advisory Consultant

Thank you all - the Javascript is working beautifully. Could you please provide us the JavaScript for Questionnaire as well - Archer 6.3 P4?

Thank you!

Aside from updating the field ids the custom object should work as is.

 Advisory Consultant

Thank you David - I'll try that.

Hello David,

I have tried updating the field ID's but I am unable to make this JavaScript work on a questionnaire. Please assist.

Any javascript errors in the browser console?

 

Also you can add alerts to your code to see where it's failing.

 Advisory Consultant

I am not receiving any errors - it is saving the record without the warning message when the end date is prior to the Start Date.

Hello David,

It appears that this javascript is working on a questionnaire only if the date field is a manual entry field. If one of the date field is a calculated field then I am unable to get this script to work. Is there a different javascript in 6.3 if one of the date field is a calculated field?