PLM 360 General Discussion

Reply
Distinguished Contributor
Brausmith
Posts: 232
Registered: ‎11-20-2008
Message 1 of 8 (268 Views)
Accepted Solution

Set Date as 'Today()'

268 Views, 7 Replies
08-25-2012 04:43 AM

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?

Regards,
Chad
Board Manager
broepke
Posts: 157
Registered: ‎01-24-2004
Message 2 of 8 (266 Views)

Re: Set Date as 'Today()'

08-25-2012 07:17 AM in reply to: Brausmith

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;

 

When you want to add dates and JavaScript it's a little harder... But not much.  Here is how it would look

 

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.

 

 



Brian Roepke
Director of PLM & PDM
Autodesk, Inc.

Distinguished Contributor
Brausmith
Posts: 232
Registered: ‎11-20-2008
Message 3 of 8 (259 Views)

Re: Set Date as 'Today()'

08-25-2012 04:12 PM in reply to: broepke

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.

Regards,
Chad
Distinguished Contributor
Brausmith
Posts: 232
Registered: ‎11-20-2008
Message 4 of 8 (257 Views)

Re: Set Date as 'Today()'

08-25-2012 06:21 PM in reply to: Brausmith

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;

Note

Date Due

Date Due Reminder (Non-editable and invisible) - Controlled via a Script at this point would be fine but I can't.

Status

Flag

 

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.

Regards,
Chad
Distinguished Contributor
Brausmith
Posts: 232
Registered: ‎11-20-2008
Message 5 of 8 (255 Views)

Re: Set Date as 'Today()'

08-25-2012 08:18 PM in reply to: Brausmith

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>'

 

END

----------

 

 

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.

Regards,
Chad
Product Support
michelle.stone
Posts: 220
Registered: ‎02-21-2012
Message 6 of 8 (252 Views)

Re: Set Date as 'Today()'

08-25-2012 09:06 PM in reply to: Brausmith

A couple links that might help - a tutorial on computed fields (though from your previous reply looks like you have the hang of it), and a link to the developer's guide on the Wiki.

 

HTH!

Michelle



Michelle Stone
PLM Product Manager
Autodesk, Inc.
*Expert Elite*
scottmoyse
Posts: 1,613
Registered: ‎06-10-2009
Message 7 of 8 (225 Views)

Re: Set Date as 'Today()'

09-12-2012 04:04 AM in reply to: Brausmith
Date created would take care of today's date automatically. Use an action script on creation to fill out the due date. But don't have it run on edit. Then once created it can be edited. But shouldn't you be using milestones for due date stuff? Regards Scott Moyse Sent from my iPhone ##################################################################################### This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal #####################################################################################
Cheers
Scott Moyse

Please use Mark Solutions!.Accept as Solution &Give Kudos!Kudos to further enhance the value of these forums. Cheers!


   

*Expert Elite*
punisher
Posts: 297
Registered: ‎10-13-2008
Message 8 of 8 (212 Views)

Re: Set Date as 'Today()'

09-28-2012 07:02 AM in reply to: Brausmith

Thanks Brian, that hooked me up.

John Evans
Autodesk Certified Professional

http://designandmotion.net

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Ask the Community