- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 11:26 AM
Hello All,
I have a requirement where I have 2 fields i.e. 'Please Select the duration' (Radio Button with 2 fields i.e. 24 Hours and 48 Hours)(Name - please_select_the_duration) and 'Start Date' (Date Time field) (Name - start_date). Based upon the radio button selected and on change of Start Date the End date field needs to be populated by adding 24 Hours or 48 Hours based upon the selectiom.
I tried multiple approaches from community, but no luck. Can someone please help me with the same.
Script Include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 04:41 AM
So in the script include you write:
var dt = new GlideDateTime(start_date);
This will only work if start_date is a string that contains a date and time in UTC time zone and format YYYY-DD-MM HH:mm:ss.
The original poster wrote:
var selected_date = new GlideDate();
selected_date.setDisplayValue(this.getParameter('sysparm_Date'));
which is way better, only it is the wrong object.
Should have been:
var selected_date = new GlideDateTime();
selected_date.setDisplayValue(this.getParameter('sysparm_Date'));
That is because GlideDateTime's setDisplayValue expects a string representing a date and time in the current user's time zone and the current user's format - whichever that format is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 04:34 AM
It will not work.
The formats that are recognized and the order in which those are tried are listed in the docs: GlideDateTime(String value).
But even those formats are interpreted as representing UTC date/times.
On client side you will only have non-UTC date/times.
Except maybe in case of users who live in GMT time zone when not during summer time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 04:42 AM
Yupp..Its working...after changing the Date format.
Timezone issue is already mentioned there.
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 04:43 AM
Are you kidding?
That is not format MMM DD,YYYY.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 04:46 AM - edited 09-23-2023 04:47 AM
Also how come the Start time is 04:39 and the End time is 21:39?
Would you care to try entering 10:00 as Start time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 04:41 AM
So in the script include you write:
var dt = new GlideDateTime(start_date);
This will only work if start_date is a string that contains a date and time in UTC time zone and format YYYY-DD-MM HH:mm:ss.
The original poster wrote:
var selected_date = new GlideDate();
selected_date.setDisplayValue(this.getParameter('sysparm_Date'));
which is way better, only it is the wrong object.
Should have been:
var selected_date = new GlideDateTime();
selected_date.setDisplayValue(this.getParameter('sysparm_Date'));
That is because GlideDateTime's setDisplayValue expects a string representing a date and time in the current user's time zone and the current user's format - whichever that format is.