Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2022-07-25 08:29 AM
Hello,
I have a sub-form containing two date fields (StartDate + EndDate), they are used in a custom object.
StartDate - current Date
EndDate - set as default to a year ahead
the custom object is preventing from the user to enter a date higher then a year, they can enter a date less.
it presenting a message to change the date if not met with the condition.
my challenge is the StartDate as it is editable as i cannot make it private, off layout or calculates as the custom object wont work.
is there a way to add/amend the custom object to make the StartDate Read only, hide the field and still prevent from entering EndDate more then year ahead,
adding my code for the date validation.
<script type="text/javascript">
var startDate = 8061, startDateValue;
var endDate = 8097, endDateValue;
var messageBoxText = "New Expiration Date cannot be more then a year ahead, Please select a valid date. ";
var messageBoxTitle = 'Warning';
var daysToCompare = +365;
var oldApplyClick, oldSaveClick
Sys.Application.add_load(function() {
// Hijack Save/Apply Buttons
$('#master_btnSave1').removeAttr('onclick').click(function() { DateCheck('save'); return false; });
$('#master_btnApply1').removeAttr('onclick').click(function() { DateCheck('apply'); return false; });
// Hijack Save and Close Button
//$('#master_btnSave1').clone().attr('id', 'master_customBtnSave1').insertBefore('#master_btnApply1');
//$('#master_btnSave1').hide();
//$('#master_customBtnSave1').unbind('click').prop("onclick", null).click(function(){ DateCheck('save');return false;});
// Hijack Save Button
//$('#master_btnApply1').clone().attr('id', 'master_customBtnApply1').insertBefore('#master_btnApply1');
//$('#master_btnApply1').hide();
//$('#master_customBtnApply1').unbind('click').prop("onclick", null).click(function(){ DateCheck('apply');return false;});
// Hide Right-Click Save and Save and Close Right-Click Menu Items
$('.rmLink:Contains("Save")').parent().parent().hide();
$('.rmLink:Contains("Save and Close")').parent().parent().hide();
});
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$btnSave1');
} else if(action == 'apply') {
ShowAnimationAndPostback('master$btnApply1');
}
}
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>
Thanks,
Naomi