Setting time to glidedatetime field type

Ramel
Mega Guru

Hi Community,

 

May I ask how can I set a default value to glidedatetime field type? In CAB Meeting > Agenda Management tab, we have 2 fields called Change Requests starting after and Change Requests starting on or before, currently the value is set using the script include CAB Meeting and it is dependent on the Meeting start time and Meeting end time. Our issue is the meeting start time and end time usually changes and that makes the Change Requests starting after and Change Requests starting on or before values change as well. What we want to do is set the time to default 18:00:00 and let the date value remain as is. Can this be achieved?

 

Thank you.

Regards,
Ramel

4 REPLIES 4

Riya Verma
Kilo Sage
Kilo Sage

Hi @Ramel ,

 

Hope you are doing great.

To set a default value for the glidedatetime field type in ServiceNow, specifically for the "Change Requests starting after" and "Change Requests starting on or before" fields in the CAB Meeting > Agenda Management tab, you can implement the following solution.

  1. Open the Form Designer for the CAB Meeting form.
  2. Locate the "Change Requests starting after" and "Change Requests starting on or before" fields.
  3. In the Default Value field for both fields, enter the following code:

 

javascript:gs.hoursToUtc("18:00:00");
​//This code sets the time portion of the glidedatetime field to 18:00:00 in the UTC format, while the date value remains unchanged.

 

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Hi Riya,

Thank you for the information. Looks like it won't work because of the script include [CAB Meeting] that does the setting of date and time, the 2 fields already has value and the default value set is ignored. Thinking of client script or BR that will change the time to 18:00:00 and whatever date set will remain unchanged.

Any idea?

 

Regards,
Ramel

@Ramel,

 

If you want to retain the date and only change the time , you can use below script , it will work for this ;

var startingAfterField = g_form.getControl('change_requests_starting_after');
var startingOnOrBeforeField = g_form.getControl('change_requests_starting_on_or_before');

// Get the current date value
var currentDate = startingAfterField.getDate();

// Set the time portion to the default value (18:00:00)
currentDate.setHours(18);
currentDate.setMinutes(0);
currentDate.setSeconds(0);

// Set the updated value for both fields
startingAfterField.setDateTimeValue(currentDate);
startingOnOrBeforeField.setDateTimeValue(currentDate);
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Ankur Bawiskar
Tera Patron
Tera Patron

@Ramel 

Can you share what did you try so far?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader