The CreatorCon Call for Content is officially open! Get started here.

Setting Actual Start and End Date

Raymond Coates
Tera Contributor

I know there are a lot of posts about the Actual Start and End Date on a project task but I'm not sure how to get things working the way I need.

 

What I would like is when a project task is moved to Work in Progress the actual start date is set to the current date and time.  Correspondingly when the project task is closed the actual end date is set to the current date and time.

 

I see the ubiquitous scenario of the actual start and end dates being set to the planned start and end dates.

 

Derive time component from planned dates is unchecked.

 

How can I get the behaviour that I am looking for?

15 REPLIES 15

AshishKM
Kilo Patron
Kilo Patron

Hi @Raymond Coates ,

You can try to write onChange client script on state field or write after update business rule on project task table.

 

(function executeRule(current, previous /*null when async*/) {
    // Check if state changed to Work in Progress
    if (current.state == 2 && previous.state != 2) { // Assuming '2' is the value for 'Work in Progress'
        current.u_actual_start_date = new GlideDateTime(); // Replace 'u_actual_start_date' with your actual field name
    }
})(current, previous);

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Thank you kindly for taking the time to reply.  It looks like there is a lot of good information in this one thread about how to approach this.  I like that your piece is focused on maintaining a client script in line with the OOB method that is currently in use.  I have some exploring to do. 😊

TejasSN_LogicX
Tera Contributor

Hi @Raymond Coates ,,

1) Use Business Rules – This is the standard approach.
Go to System Definition → Business Rules → New

Table: pm_project_task

When: before

Conditions: State changes to "Work in Progress"

Script:
if (current.state == 'work_in_progress' && !current.actual_start_date) {
current.actual_start_date = new GlideDateTime();
}
This sets the actual start date only if it’s not already set.



and now
Another Business Rule:

Table: pm_project_task

When: before

Condition: State changes to "Closed"

Script:
if (current.state == 'closed' && !current.actual_end_date) {
current.actual_end_date = new GlideDateTime();
}
This ensures the actual end date is set only once, at closure.

and pls Make sure you check your state values in your instance because sometimes “Work in Progress” or “Closed” may have different internal values.

@TejasSN_LogicX, thank you kindly for this information.  I think this will help me with the path forward.  Once I have more information from @Namita Mishra reply I will see what the path forward is for my situation.