compare end date and start date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2024 06:14 AM
Hello, I have a requirement for the Record Producer. There are two variables: "Proposed Effective Date" and "Expected End Date," both of which are of the "Date" type variable.
1)Requirement is that the "Expected End Date" must be greater than the "Proposed Effective Date." If this condition is not met:
- Clear the value of "Expected End Date" whenever the "Proposed Effective Date" is changed.
- Display the error message: "Expected End Date is smaller than Proposed Effective Date."

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2024 06:40 AM
You have two option for the comparison of dates.
1. No Code Data compare UI Policy
2. Script Include with client scripts
As for Clearing Expected End Date you could try doing that in a client script but know that you cannot see the previous value to verify that it was actually changed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2024 06:51 AM
Hi @Community Alums
Create a script include:
Script Include name: DateTimeUtils
client callable: true
Script:
var DateTimeUtils = Class.create();
DateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
compareEndDate: function() {
var check = false;
var startDate = this.getParameter('sysparm_start_date');
var endDate = this.getParameter('sysparm_end_date');
var gdt1 = new GlideDateTime(startDate);
var gdt2 = new GlideDateTime(endDate);
check = gdt1.before(gdt2);
return check;
},
type: 'DateTimeUtils'
});
2. Create a client script onchange of proposed effective date
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var startdate = g_form.getValue('expected_end_date');//change the variable name
if(startdate == '')
{
g_form.clearValue('proposed_effective_Date');//change the variable name
g_form.showFieldMsg('proposed_effective_Date','Please select Expected end date first date first','error');/change the variable name
return;
}
else
{
var ga = new GlideAjax('global.DateTimeUtils');
ga.addParam('sysparm_name','compareEndDate');
ga.addParam('sysparm_start_date',startdate);
ga.addParam('sysparm_end_date',newValue);
ga.getXML(responseCallBack);
}
function responseCallBack(response)
{
var ans = response.responseXML.documentElement.getAttribute('answer');
if(ans== false || ans == 'false')
{
g_form.clearValue('proposed_effective_Date');//change the variable name
g_form.showFieldMsg('proposed_effective_Date','Please select a future date','error');/change the variable name
}
}
}