- 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 03:44 AM
Issue is that I have multiple users and they are using different date format based upon there preference and country location. I need to design a script which works based upon the date preference of the user and for all the date preference. Can you please help me how I can design this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 04:03 AM - edited 09-23-2023 04:06 AM
Hint: the problem is with the input, not the output - or rather how you take in the start date.
Hint2: the original poster does it way better, only using the wrong object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 04:13 AM
Hi @-O-
Indeed...!!
Date time format will be taken from input and its working absolutely fine for me.
For @Shrey hurana its not working.
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:22 AM - edited 09-23-2023 04:25 AM
You mean you have changed the date/time format of your user profile to MMM DD,YYYY HH:MM:SS and it worked. Than changed it to dd/MM/yy HH:mm:ss and it still worked?
I mean the idea here is the solution to work under any condition, not just for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2023 04:28 AM
This test case I have not checked.
Let me check.
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates