First, I still consider myself as a novice when it comes to JavaScript.
I'm looking to get the current day of the week in a value (Monday, Tuesday, etc.) in either forms or workflow. (The process starts in forms and passes info to workflow, where I'd eventually need/like to have the day of the week value.)
I have it working with a slightly modified version of the solution exchange example found here. (I'll post how I have it below).
Is there a native way within forms or workflow to get the current day of the week value? I was hoping to use the EEEE version of token formatting, but since workflow uses .net, it doesn't support that version of formatting.
If there isn't a native way, perhaps there is a way to improve on the modifications I made to the linked page above? For context, this is an automatic transfer agreement form I'm building. If it is a new agreement, there is a start date field, if it is a cancellation, there is an original date field.
For new agreements:
$(document).ready(function () { function findDay() { var d = new Date(); var weekday = new Array(7); weekday[0] = "Sunday"; weekday[1] = "Monday"; weekday[2] = "Tuesday"; weekday[3] = "Wednesday"; weekday[4] = "Thursday"; weekday[5] = "Friday"; weekday[6] = "Saturday"; var n = weekday[d.getDay()]; $('.dayWeek select').val(n); $('.dayWeek select').trigger('change'); } $('.startDate').on('blur', 'input', findDay); });
For Cancellations:
/* Get Current Day of the Week for Cancellations*/ $(document).ready(function () { function OriginalDay() { var d = new Date(); var weekday = new Array(7); weekday[0] = "Sunday"; weekday[1] = "Monday"; weekday[2] = "Tuesday"; weekday[3] = "Wednesday"; weekday[4] = "Thursday"; weekday[5] = "Friday"; weekday[6] = "Saturday"; var n = weekday[d.getDay()]; $('.dayWeek select').val(n); $('.dayWeek select').trigger('change'); } $('.originalDate').on('blur', 'input', OriginalDay); });
(The dropdown field containing the days of the week has the CSS class of dayWeek, while the Start Date field has startDate and Original Date field has originalDate.)
Is there a way that we could modify either script where it is reliant on a change from another field, not specifically a date field type? Or even better, just have it show the current day of the week on page load? (I should perhaps note that the day of the week field is going to be hidden. It is just something I want to pass along to workflow.)
Thanks everyone for any help!