With a Date field, is there a way to set the default date to 'today()'?
Further to this, is it also possible to set a default date as 'today()+7', or what ever to date is in X number of days?
Solved! Go to Solution.
There isn't a way to do this directly in the field. However, you can create a small script that will do that - make it an action script and set it as part of the "create" bevaior. Inside the tenant there are a bunch of examples to pick from. Particularily where the milestones are created. "createMileStones" Library script. Check this one out.
The script could be as simple as the following for setting today's date
var today = new Date();
item.MY_TODAY_FIELD = today;
var nextweek = new Date();
var dayOfMonth = nextweek.getDate();
nextweek.setDate(dayOfMonth + 7);
item.MY_NEXT_WEEK_FIELD = nextweek;
Remember - Google examples like this and you'll find tons of samples out there.
Director of Product Lifecycle Management
Thanks for the reply Brian. Unfortunately this is not quite what I am after, let me explain further.
When I referred to a default date value, I want the field to be pre-populated at the time the user is creating a New workspace item, not after they press the Save button.
In my example, I would like the user to press New to start the creation process. They are presented with the fields to fill out, but I want my Date and Date Due fields to be pre-populated with todays date and a date in 7 days respectively. This way they don't need to fill them out each time. But, I also want to user to be able to override the values if they are not correct, i.e. maybe the Due Date should be in 3 days.
It's almost as though we need a Workspace Behaviour for Script to run at item spawing.
The other thing is that Scripts only seem to run at the Item Details level in a Workspace and not in the Grid view, which is where I need this to happen.
To give a clearer picture of what I want to do, I would like to use the Grid view for recording some general notes and actions. This tab contains the following fields;
Date Due Reminder (Non-editable and invisible) - Controlled via a Script at this point would be fine but I can't.
I would like the Date Due to be 7 days after the current date, but offer the user the flexibility to change it. The Date Due Reminder would be auto-calculated to be 2 days prior to the Date Due.
The Flag would then be set by some rules including the Status field, but in general it would be set by; Green=on track, Orange=within the 2 day reminder period, Red=Overdue.
Looks like I may have spoke too soon on my last reply. I seem to have figured it out by using a Computed Field Formula. After some testing it is working pretty well, and thought I'd share the result.
STATUS field - Picklist 3 options (Complete, In Progress, No Action Required)
FLAG field - Computed Field Formula
CASE WHEN (STATUS = 1) OR (STATUS = 3) THEN '<span style="text-align:center; line-height:30px; color:gray; background:gray; width:100%; float:left; height:20px;">GRAY</span>'
WHEN (STATUS = 2) AND (DATE_DUE > getdate()) AND (DATE_DUE < (getdate()+2)) THEN '<span style="background: orange; color: orange; width:100%; float:left; height:20px;">ORANGE</span>'
WHEN (STATUS = 2) AND (DATE_DUE < getdate()) THEN '<span style="background:red; color:red; width:100%; float:left; height:20px;">RED</span>'
ELSE '<span style="text-align:center; line-height:30px; color:green; background:green; width:100%; float:left; height:20px;">GREEN</span>'
The hardest part is working out the syntax of the code which PLM will accept. Is there a reference in the Help to this? I've looked but have not been able to find anything.