- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 11:10 AM - edited 12-14-2023 11:24 AM
I have a record producer that is using an out-of-the-box script include which has a Read-only protection policy. For my particular needs, I had to alter that script include so I made a copy. However, I have not altered the compareDates function code at all.
When I submit the record producer, there is on onSubmit client script which calls the script include, comparing two dates on the request (Start Date and End Date) to validate that the start date is before the end date. The function in the script include also calls the OOB DateUtils.compareDates function.
In testing, we entered a start date in 2023 and an end date in 2024 (an anticipated end date in the record producer), and the validation is saying the start date must be earlier than the end date.
I added a gs.info line to the script include and the dates are being converted from the record producer to something that looks completely odd to me. Can anyone provide any insight?
ETA Log message: AV - start date is 0018-08-16 end date is 0008-08-16
Here is the code:
Catalog Client Script Date Validation (onSubmit):
function onSubmit() {
if (g_scratchpad.areDatesValid) {
return true;
}
g_scratchpad.actionName = g_form.getActionName();
g_scratchpad.areDatesValid = false;
var variableDescriptor = g_scratchpad.coi.variableDescriptor;
var SUBCATEGORY_NON_WFRD = variableDescriptor.conflictTypes.nonWFRD.id;
var SUBCATEGORY_BOARD_SERVICE = variableDescriptor.conflictTypes.boardService.id;
var SUBCATEGORY_OUTSIDE_EMPLOYMENT = variableDescriptor.conflictTypes.outsideEmployment.id;
var SUBCATEGORY_GOVERNMENT_OFFICIAL = variableDescriptor.conflictTypes.governmentOfficial.id;
var SUBCATEGORY_FINANCIAL_INTEREST = variableDescriptor.conflictTypes.financialInterest.id;
var CONFLICT_TYPES = [SUBCATEGORY_OUTSIDE_EMPLOYMENT, SUBCATEGORY_BOARD_SERVICE, SUBCATEGORY_NON_WFRD, SUBCATEGORY_GOVERNMENT_OFFICIAL, SUBCATEGORY_FINANCIAL_INTEREST];
var conflictType = g_form.getValue('conflict_type');
var startDate = '';
if (conflictType == '2161f2481bc9bd10c7f16316624bcbd2') { //Financial Interest
startDate = g_form.getValue('date_interest_acquired_coi');
} else {
startDate = g_form.getValue('start_date');
}
var endDate = g_form.getValue('end_date');
if (CONFLICT_TYPES.indexOf(conflictType) > -1 && startDate && endDate) {
var coiAjax = new GlideAjax('sn_lg_coi.LegalCoiWfrdAjax');
coiAjax.addParam('sysparm_name', 'compareDates');
coiAjax.addParam('sysparm_start_date', startDate);
coiAjax.addParam('sysparm_end_date', endDate);
coiAjax.setScope('sn_lg_coi');
coiAjax.getXMLAnswer(function(answer) {
var result = JSON.parse(answer);
if (result === 1) {
var errorMessage = getMessage('Start date must be earlier than the End date.');
g_form.addErrorMessage(errorMessage);
return;
}
g_scratchpad.areDatesValid = true;
g_form.submit(g_scratchpad.actionName);
});
} else {
return true;
}
return false;
}
LegalCoiWfrdAjax.compareDates:
compareDates: function() {
var startDate = this.getParameter('sysparm_start_date');
var endDate = this.getParameter('sysparm_end_date');
var startGlideDate = new GlideDate();
startGlideDate.setValue(startDate);
var endGlideDate = new GlideDate();
endGlideDate.setValue(endDate);
gs.info('AV - start date is ' + startGlideDate + ' end date is ' + endGlideDate);
return JSON.stringify(DateUtils.compareDates(startGlideDate, endGlideDate));
},
DateUtils.compareDate:
DateUtils.compareDates = function(date1, date2) {
if (date1 > date2)
return 1;
else if (date1 < date2)
return -1;
return 0;
};
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 01:04 PM
I think GlideDate expects the date to be in System Date Format
For ex our system date format is set to
If I use this format, I get the right date in the background script
If I use any other format, I get a wrong date
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 11:31 AM
Following blog should help
You can do a direct compare instead of doing GlideDate. Check the CompareDate function in the blog.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 12:51 PM
Hi Sanjiv,
Thank you for the link to the blog. I definitely appreciate all the use cases for dates. Since I had to create my own script include to handle our specific needs, I can definitely try to update the compare date script so it functions as expected.
What's concerning is that the OOB script uses GlideDate and doesn't seem to validate as expected. I even tested an OOB form and found the same issue. Odd.
Do you know what GlideDate does to a regular date? Why are the dates converting from 12-14-2023 to 0018-08-16?
Thanks!
Amy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 01:04 PM
I think GlideDate expects the date to be in System Date Format
For ex our system date format is set to
If I use this format, I get the right date in the background script
If I use any other format, I get a wrong date
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 02:35 PM
Oh, I see. Our date format is set to MM-DD-YYYY in system properties. I will keep trying the getByFormat to change it into the correct format, I just haven't figured out where to put that yet. Thanks!