Issue with Catalog Item Client Script – Inconsistent Date Difference Validation

SakshyaR
Tera Contributor

Dear Community,

I am reaching out regarding a catalog item that includes a client-side script used to validate the difference between two date fields. The script is intended to ensure that the difference between these dates does not exceed 30 days.

However, we are currently facing an inconsistent behavior. At times, the validation works correctly, while at other times, it does not trigger or allows date differences greater than 30 days without any error message. This issue occurs randomly, making it difficult to identify a clear pattern.

We have checked the script logic, and it appears to be correct.

Below is the client script that is on change

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   
    if(g_form.getValue('date_that_the_server') !='')
        {
    g_form.hideFieldMsg('back_to_sleep_status');
   
    var gaDate = new GlideAjax('ANCatalogItemServiceAjax');
    gaDate.addParam('sysparm_name','dateValidationMothBalledSleeperService');
    gaDate.addParam('sysparm_date', newValue);
    gaDate.addParam('sysparm_compare_date', g_form.getValue('date_that_the_server'));
    gaDate.addParam('sysparm_days_to_add', 30);
    gaDate.getXMLAnswer(dateValidation);
}
function dateValidation(answer) {
    if(answer !='validdate'){
        g_form.clearValue('back_to_sleep_status');
        g_form.showFieldMsg('back_to_sleep_status',answer);
    }
}
}
 
Any insights or recommendations would be greatly appreciated.
11 REPLIES 11

Hello,
Have you done any testing by adding logs? For example:

  • What values are you sending?

  • What values are you expecting from the Script Include?

  • What values are actually coming from the Script Include when the issue occurs?

SakshyaR
Tera Contributor

This configuration is already in use and is working as expected; however, we have been facing issues for the past few days. Specifically, when we select June 2nd, 3rd, 4th, and 5th, as well as the same dates for the following month, we encounter problems. For other dates, the system is functioning as expected.