Date Validation error in Record Producer

Aram Sosa
Tera Expert

Hello folks!
I have a record producer with the field “Start date and End date”, which is validated by the following Catalog client script:

 

AramSosa_1-1713903213032.png

 

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:

AramSosa_2-1713903253092.png

 

Any help is greatly appreciated!

5 REPLIES 5

Karunakaran
Mega Guru

Hi @Aram Sosa Can I take a look at the script include?

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.

For these lines.
var coiAjax = new GlideAjax('sn_lg_coi.LegalCoiAjax');
        coiAjax.addParam('sysparm_name', 'compareDates');

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