The Zurich release has arrived! Interested in new features and functionalities? Click here for more

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?

3 REPLIES 3

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

tejas1111
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.

Namita Mishra
ServiceNow Employee
ServiceNow Employee

Hi @Raymond Coates ,

Thanks for connecting with community.

 

Your expected behaviour is out of the box behaviour as well. This means when a project task is moved to Work in Progress the actual start date is set to the current date and time and when the project task is closed the actual end date is set to the current date and time.

 

Please check if there is any customization on your instance.

 

Thank You!

Namita Mishra