- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2016 09:34 AM
I am allowing the user to select a date with the calendar widget and in an effort to to revert whatever date they chose to the previous Monday my plan is to us a switch that switches on the day of the week they choose. I am able to successfully bring in the date selected:
var selected_date = g_form.getValue('week_starts_on');
but I am unable to get this converted to a day of the week. I have tried to use the following (unsuccessfully):
var selected_day=selected_date.getDay();
as I know var selected_day=new Date().getDay(); works fine.
I'm willing to consider other alternatives but this seems to be an option that will work if i can just turn that user selected date into the day of week that it corresponds to.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2016 07:19 PM
HI Joe,
Default Date() function available from javascript can provide you the day of the week based on date selected by the user. You wont require to make GlideAjax calls for this sure. An example of it which is relevant for you is below. You can refer to my earlier post as well for this
var day
var selected_date = g_form.getValue('week_starts_on'); // get the value entered by user
var dObj = new Date(selected_date); // initialize the object dObj for Date() method and pass the user selected date to it
var selected_day = dObj.getDay(); // return 0 for sunday, 1 for monday and store it in selected_day variable.
I have just tested it on javascript executor of ServiceNow (press control+shift+j to launch it on the form you are working on) and it worked perfect for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2016 06:42 AM
You are correct and this is exactly what I needed to solve the problem. I then used GlideAjax to complete the rest of my work so thank you to Goran as well.