Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2018-05-09 04:50 PM
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!
2018-05-09 05:48 PM
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>
2018-05-10 08:25 AM
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
2018-05-10 12:56 PM
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!
2018-05-10 01:01 PM
Aside from updating the field ids the custom object should work as is.
Advisory Consultant
2018-05-10 02:41 PM
Thank you David - I'll try that.
2018-05-14 02:35 PM
Hello David,
I have tried updating the field ID's but I am unable to make this JavaScript work on a questionnaire. Please assist.
2018-05-14 02:45 PM
Any javascript errors in the browser console?
Also you can add alerts to your code to see where it's failing.
Advisory Consultant
2018-05-16 06:00 PM
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.
2018-05-24 06:19 PM
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?