Date Validation error in Record Producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 01:16 PM
Hello folks!
I have a record producer with the field “Start date and End date”, which is validated by the following Catalog client script:
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_OUTSIDE_EMPLOYMENT = variableDescriptor.conflictTypes.outsideEmployment.id;
var SUBCATEGORY_BOARD_SERVICE = variableDescriptor.conflictTypes.boardService.id;
var CONFLICT_TYPES = [SUBCATEGORY_OUTSIDE_EMPLOYMENT, SUBCATEGORY_BOARD_SERVICE];
var conflictType = g_form.getValue('conflict_type');
var 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.LegalCoiAjax');
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;
}
The problem is that when I put these specific dates when filling the form, I get this error and it does not allow me to send it:
Any help is greatly appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 01:32 PM
Hi @Aram Sosa Can I take a look at the script include?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 01:39 PM
Sorry if I misunderstand the question, which script include do you want to see? The Catalog script that is in charge of the validation of the field where the error is, I added it in the description.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 01:44 PM
For these lines.
var coiAjax = new GlideAjax('sn_lg_coi.LegalCoiAjax');
coiAjax.addParam('sysparm_name', 'compareDates');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 01:49 PM
Of course! Here it is:
var LegalCoiAjax = Class.create();
LegalCoiAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
checkUserHasExistingCoiRecords: function() {
return LegalCoiUtils.checkUserHasExistingCoiRecords(gs.getUserID());
},
getCoiVariables: function() {
var coiId = this.getParameter('sysparm_coi_id');
var coiRecord = sn_lg_ops.LegalOperationsUtils.getGRSecureBySysID(LegalCoiConstants.TABLE_COI, coiId);
if (coiRecord) {
var coiVariables = LegalCoiUtils.getVariablesObject(coiRecord.getValue('legal_request'));
if (coiVariables) {
coiVariables.start_date = {
name: 'start_date',
value: coiRecord.getValue('start_date'),
displayValue: coiRecord.getDisplayValue('start_date')
};
coiVariables.end_date = {
name: 'end_date',
value: coiRecord.getValue('end_date'),
displayValue: coiRecord.getDisplayValue('end_date')
};
return JSON.stringify(coiVariables);
}
}
return null;
},
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);
return JSON.stringify(DateUtils.compareDates(startGlideDate, endGlideDate));
},
type: 'LegalCoiAjax'
});
By the way, I can not edit this since is read-only based on its protection policy