Skip to main content



No record found.

Dynamics 365 general forum

Possible to track time spent on each contact?

Posted on by 775

Hello, we would like to track the amount of time spent on a contact and all that contact's associated records. We are wanting to know more about how much time we are spending on each person, especially those contacts who are having a lot of time spent on them. It's not a perfect metric, but we thought the amount of time spent on the contact form and then each associated record would give a good idea. 

Idk if it would be possible to use javascript to update a field each time a record is opened/closed, and then add the end of each day sum all the fields from all the associated records of a contact?

Any thoughts of if this sort of time tracking is possible, and if so, what's the simplest way?

  • Verified answer
    Linn Zaw Win Profile Picture
    Linn Zaw Win 3,403 on at
    RE: Possible to track time spent on each contact?

    I have an idea but probably it will involve a lot of API requests depending on how frequently do you want to trigger. It will also involve quite a lot of customisation depending on how many associated entities of contact you want to record. Implementing that may slow down the system if there are a lot of records and it may not record the actual time spent for certain scenarios (e.g. the user opened the contact form and go out for coffee break). I suggest not to implement it unless this is a mission-critical requirement of the project. 

    The idea is to keep track of the record opened/closed time in a field and create a custom activity against the record. We can trigger a function at onLoad event of the form to populate the record opened time but there is no onClose event. The workaround solution is to update the current time to the record closed time in a certain interval and onSave event. Auto-save triggers when the user navigates out of the record but it will not trigger when the browser/tab is forced closed by the user and those time will not be logged in that case. This will not work well if multiple users open up the same record at the same time.

    1. Create new hidden date/time fields (e.g. xyz_openedon, xyz_closedon) on the Contact (and each associated record to track)
    2. onLoad of the form, set the current time to xyz_openedon
    3. Set xyz_closedon with current time in certain interval (e.g. 2 minutes) using setTimeOut (code sample below)
    4. onLoad of the form, set the current time to xyz_closedon
    5. Since the value is updated every 2 minutes in step 3, the auto-save of the record is always triggered.
    6. Create a new custom entity.
    7. Create an automated flow which triggers on Contact (or each associated entity) filtering on xyz_closedon attribute
    8. The flow will create a custom entity record and set
      1. actualstart = xyz_openedon
      2. actualend = xyz_closedon
      3. owner = modifiedby
      4. regarding = Contact (or other associated entity)
    9. Before create a new record for step 8, find if there is any existing record with same actualstart and regarding
      1. this is to prevent the new record to be created every auto-save triggers
      2. if there is any existing record with same actualstart, update the actualend = xyz_closedon instead
    10. Create another scheduled flow which triggers at the end of the day to retrieve the custom activities created for the whole day and roll up to the related contact.

    The modifiedon of the contact and associated records will always be updated even if the user opens the record and just view because of the script and auto-save.

    function setClosedOn()
    	formContext.getAttribute("xyz_closedon").setValue(new Date());
    	window.setTimeout(setClosedOn, 120000);

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans