function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chris GrebowiecChris Grebowiec 

Adding a date and time stamp when a task is completed.

Has anyone created code to implement a custom field on tasks that creates a date and time stamp when it is saved as complete?  
MissedCallMissedCall
Hi Chris,

Is there a specific reason why you are talking code here? This can be achived used workflow rules with a field update. 

All i would do is,
 -- Create a custom field of date/time data type on acitivity and add it to task layout
 -- Create a workflow rule on task, choose whatever option is appropriate for you on when to run the rule and condition is status equals completed
 -- Create a field update on task object and choose above created field, then in the specify new field value select formula and select last modified by or whatver field works for you
 -- Tie the above field update with workflow rule and activate it. 

Let me know if it helps!
David ZhuDavid Zhu
You can add a custom field on Task object with datatime data type. i.e we call it "completedDateTime".
Then use the trigger to update the value:
 
trigger TaskCompleted on Task (before insert,before update) {

        for (task tsk : trigger.new)
        {
            if (tsk.status == 'Completed')
            {
                tsk.CompletedDateTime__c = system.now();
            }
        }
}

 
Shailesh DeshpandeShailesh Deshpande
You do not need a code here. You can achieve using workflow field update.

1. First create a custom date time field say Activity_Completed_On__c  on Activities.
2. Create a workflow rule on Task object with Rule criteria to "Formula that evaluates to true" and set it as ISCHANGED(Status)

3. In Workflow actions select field update. Select the field created in step1 as "Field to update" and in value use formula as below:
IF( 
AND( 
ISPICKVAL(Status,'Completed'), 
ISNULL(Activity_Completed_On__c) 
) , 

NOW(), 

IF(ISPICKVAL(Status,'Completed'),Activity_Completed_On__c, null ) 
)

Thanks,
Shailesh.
Chris GrebowiecChris Grebowiec
ISCHANGED(Status) is giving me an error stating "Function ISCHANGED may not be used in this type of formula".  So I am unable to get to step three.  Ideas?  
Curtis ButrickCurtis Butrick
Chris - If you are still stymied, (or for anyone else stumbling upon this thread), You need to set your Evaluation Criteria to Evaluate teh Rule with a Record is "Created, and every time it's edited", not, "created, and any time it's edited to subsequently meet criteria"
Ankit Goyal1Ankit Goyal1
Chris - Try, ISCHANGED(TEXT(Status))