Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to mapping the date and hour from catalog to ritm

scl_amorale
Tera Expert

Hi I need to mapping the date and hour from catalog to ritm, like this:

variable from catalog
u_fecha = "13-03-2025"
u_horario = "11:30"

field  RITM:
u_std_fecha_programada_inicio = 2025-03-13 11:30:00
u_std_fecha_programada_fin = 2025-03-13 12:30:00


SCRIPT:

var fecha = current.variables.u_fecha;  // Formato esperado: YYYY-MM-DD
var hora = current.variables.u_horario; // Formato esperado: HH:mm (24h)

// Validar que los valores existen
if (fecha && hora) {
    // Crear fecha de inicio combinando fecha y hora
    var fechaInicio = new GlideDateTime(fecha + " " + hora);

    // Clonar fechaInicio y sumarle 60 minutos (3600 segundos)
    var fechaFin = new GlideDateTime(fechaInicio);
    fechaFin.addSeconds(3600);

    // Asignar valores sin usar update() para evitar loops
    current.setValue("u_std_fecha_programada_inicio", fechaInicio);
    current.setValue("u_std_fecha_programada_fin", fechaFin);
}

1 ACCEPTED SOLUTION

It's work on mine. Are these two variables in the correct format as the comment next to them?
var fecha = current.variables.u_fecha;  // Formato esperado: YYYY-MM-DD
var hora = current.variables.u_horario; // Formato esperado: HH:mm (24h)Screenshot 2025-03-17 at 10.13.54.png

View solution in original post

3 REPLIES 3

phgdet
Mega Sage
Mega Sage

Hi, scl_amorale
Your script is missing seconds when add time to the variable.
Update the line 6 to this below code.

 

var fechaInicio = new GlideDateTime(fecha + " " + hora + ":00");

 



scl_amorale
Tera Expert

Hi , is not working, for example I selected in my catalog  "Horario: 11:30",  but in RITM  appear 8:30  and 9:30. Should be appear 11:30 and 12:30

 

scl_amorale_0-1741958398412.png

 

(Horario is a text variable)

scl_amorale_1-1741958703733.png

 

 

It's work on mine. Are these two variables in the correct format as the comment next to them?
var fecha = current.variables.u_fecha;  // Formato esperado: YYYY-MM-DD
var hora = current.variables.u_horario; // Formato esperado: HH:mm (24h)Screenshot 2025-03-17 at 10.13.54.png