You are viewing limited content. For full access, please sign in.

Question

Question

Current Day of the Week

asked on May 31, 2018

First, I still consider myself as a novice when it comes to JavaScript. smiley

 

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!

0 0

Answer

SELECTED ANSWER
replied on May 31, 2018 Show version history

Since you're able to handle this in Workflow, you're in luck! It would actually be much easier because there is built-in functionality for this exact thing.

Workflow's token editor provides access to date/time formatting that will give you exactly what you want without much difficulty.

For example, you take your date/datetime value and store that to a token, then open up the Token Editor (right-click the token value) and apply your formatting.

In your case, you would enter "dddd" which gives you the full text name of the day of the week based on the server's regional settings.

You can find more information about formatting for numbers, date/time, etc. here.

3 0
replied on May 31, 2018 Show version history

That is perfect and so much easier.   I think I was looking too much for E based tokens due to the icu standard of formatting.  (Linked to here.)  I likely kept skipping past the d based formatting because of that.

 

Thanks!

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.