Date and time assigned in the calendar

scl_amorale
Tera Expert

Hello, I need help. When I select a date and time already assigned in the calendar from the catalog, the error "Dates and times assigned" appears and that is correct. But the script works for some days, for example, 18-03-2025, but on other days, it doesn't detect that they have already been assigned. For example, I selected the date 19-03-2025, and the time 15:30, but that date is already selected, but the script doesn't detect it.

scl_amorale_0-1742242051987.png

SCRIPT:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    //Type appropriate comment here, and begin script below
     var ga = new GlideAjax('ETL_Clase_Catalogos');
    ga.addParam('sysparm_name', 'fnValidaFechaProj');
    ga.addParam('sysparm_fecha', g_form.getValue('u_fecha'));
    ga.addParam('sysparm_hora', newValue);
    ga.getXML(respuestaServer);

    function respuestaServer(response) {
        var answerFromXML = response.responseXML.documentElement.getAttribute('answer');
       
        if (answerFromXML == 'false') {
            alert('Hora y fecha ya asignada.');
            g_form.clearValue('u_fecha');
            g_form.setValue('u_horario', null, '--Seleccionar');
            g_form.showFieldMsg('u_fecha','Hora y fecha ya asignada.','error');
        }      
    }
}

 

 

SCRIPT INCLUDE

fnValidaFechaProj: function() {
        var fecha_cal = this.getParameter('sysparm_fecha');
        var sysparm_hora = this.getParameter('sysparm_hora');
        //var sysparm_origen = this.getParameter('sysparm_origen'); // Nuevo parámetro

        var gdt_date = new GlideDateTime(fecha_cal + " 01:00:00");

        var dd = String(gdt_date.getDayOfMonthUTC());
        if (dd.length == 1)
            dd = '0' + dd;

        var mm = String(gdt_date.getMonthUTC());
        if (mm.length == 1)
            mm = '0' + mm;

        var yyyy = gdt_date.getYearUTC();
        var fecha_busqueda = yyyy + '-' + mm + '-' + dd;

        var gr = new GlideRecord('u_ent_project');
        gr.addEncodedQuery("u_tipo_registro=calendario^u_start_dateON" + fecha_busqueda + "@javascript:gs.dateGenerate('" + fecha_busqueda + "','start')@javascript:gs.dateGenerate('" + fecha_busqueda + "','end')^u_activo=true^u_date_choice=" + sysparm_hora);
        gr.query();
        if (gr.next()) {
            return false;
        }

        return true;
    },
1 ACCEPTED SOLUTION

palanikumar
Mega Sage

Hi,

Your calculation is based on UTC. Is your timezone in GMT? otherwise you may need to convert based on your time zone

Thank you,
Palani

View solution in original post

2 REPLIES 2

palanikumar
Mega Sage

Hi,

Your calculation is based on UTC. Is your timezone in GMT? otherwise you may need to convert based on your time zone

Thank you,
Palani

scl_amorale
Tera Expert

thansk.