Important Update: Community URLs redirect issues are partially resolved. Learn More. .
2 weeks ago
I have 2 manually updated date fields that require data validation rules.
Date field 1 - the value must be prior to or equal to today
Date field 2 - the value must be equal to or greater than Date field 1
I have searched through the site, but most of the relevant references contain links to the old community.rsa site, so they are not valid.
I have very limited experience with custom code creation, so might require detailed instructions.
I don't know if it's possible for the validation to occur before the user clicks Save, or if it's possible for the record to now be saved if the conditions are not met.
Need to produce a pop-up message box to the end user.
TIA for any direction.
a week ago - last edited a week ago
The format of the other dates in the calc is "22/04/2024" prior to going into that convertToDate function (At least it is for me, unsure if the format follows your local format, or if it's D/M/Y for everyone), so you just need to make sure however you're getting today's date, it ends up in the same format. I got it working with the following bits of code, whether there's a more efficient way to do it, probably.
const date= new Date();
let day = date.getDate();
let month = date.getMonth() + 1;
let year = date.getFullYear();
Date3Val=`${day}/${month}/${year}`;
console.log("Date3Val: " + Date3Val);
Date3Date=convertToDate(Date3Val);
console.log("Date3Date: " + Date3Date);
2 weeks ago
Hello @DavidPetty , any advice?
2 weeks ago
This is the code we use for date validation: Date Comparison in Archer 6.3 - Archer Community - 443212 (archerirm.community)
Here's our actual code we use for validating dates on our complaints application. Hopefully you're able to tweak it to work even without much coding knowledge.
<script type="text/javascript">
//Date1 should be earliest date, Date2 next earliest, etc
var Date1= 27717;
//for this app, Date1 = Date Complaint Received
var Date2= 27728;
//Date2 = Date Acknowledged
var Date3= 27741;
//Date3 = Date Response Sent
//this code does not work on calculated or system fields, only manual entry date fields
//for use in other apps, just update the field ids in the variables above, and ensure the warning messages are accurate
Sys.Application.add_load(function() {
$('div[id*="f' + Date1 + 'cdp"]').change(function() {
checkDates(Date1);
});
$('div[id*="f' + Date2 + 'cdp"]').change(function() {
checkDates(Date2);
});
$('div[id*="f' + Date3 + 'cdp"]').change(function() {
checkDates(Date3);
});
});
function checkDates(idToBlank) {
Date1Val=$('div[id*="f' + Date1 + 'cdp"]' + ' > input:nth-child(1)').val();
Date1Date=convertToDate(Date1Val);
Date2Val=$('div[id*="f' + Date2 + 'cdp"]' + ' > input:nth-child(1)').val();
Date2Date=convertToDate(Date2Val);
Date3Val=$('div[id*="f' + Date3 + 'cdp"]' + ' > input:nth-child(1)').val();
Date3Date=convertToDate(Date3Val);
if (Date1Date!=null) {
if (Date2Date!=null) {
if (Date1Date>Date2Date) {
var msg = "The Date Acknowledged cannot be before the Date Complaint Received";
var title = 'Warning';
WarningAlert(msg,title);
nullThisID(idToBlank)
}
}
if (Date3Date!=null) {
if (Date2Date>Date3Date) {
var msg = "The Date Resolved cannot be before the Date Acknowledged";
var title = 'Warning';
WarningAlert(msg,title);
nullThisID(idToBlank)
}
}
}
}
function nullThisID(thisID) {
$('div[id*="f' + thisID + 'cdp"]' + ' > input:nth-child(1)').val('')
}
function convertToDate(aDate) {
dataSplit=aDate.split("/");
returnDate=null;
if (dataSplit.length==3) {
returnDate = new Date(dataSplit[2],dataSplit[1],dataSplit[0]);
}
return returnDate;
}
</script>
That code is for 3 dates. If you only care about comparing 2 dates, you can just remove these two parts from the code:
Date3Val=$('div[id*="f' + Date3 + 'cdp"]' + ' > input:nth-child(1)').val();
Date3Date=convertToDate(Date3Val);
if (Date3Date!=null) {
if (Date2Date>Date3Date) {
var msg = "The Date Resolved cannot be before the Date Acknowledged";
var title = 'Warning';
WarningAlert(msg,title);
nullThisID(idToBlank)
}
}
a week ago
@JordanG ,
Thank you, this works perfect to compare 2 date fields.
The other component I need is to compare the date field to the current date.
This produces:
var Date3 = new Date().toJSON().slice(0, 10);
console.log(Date3); // "2024-04-22"
But I'm not sure if that is a correct reference, or how I need to compare it to Date 1?
TIA
a week ago - last edited a week ago
The format of the other dates in the calc is "22/04/2024" prior to going into that convertToDate function (At least it is for me, unsure if the format follows your local format, or if it's D/M/Y for everyone), so you just need to make sure however you're getting today's date, it ends up in the same format. I got it working with the following bits of code, whether there's a more efficient way to do it, probably.
const date= new Date();
let day = date.getDate();
let month = date.getMonth() + 1;
let year = date.getFullYear();
Date3Val=`${day}/${month}/${year}`;
console.log("Date3Val: " + Date3Val);
Date3Date=convertToDate(Date3Val);
console.log("Date3Date: " + Date3Date);
a week ago
Thank you. I was able to get this to work.