Setting time to glidedatetime field type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 01:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 01:57 AM
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.
- Open the Form Designer for the CAB Meeting form.
- Locate the "Change Requests starting after" and "Change Requests starting on or before" fields.
- 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.
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 02:27 AM - edited 06-20-2023 02:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 02:46 AM
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);
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 02:57 AM
Can you share what did you try so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader