web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Calculate Total Case time

(0) ShareShare
ReportReport
Posted on by 165

Hi, 

I need to present in a report the total time between the date when the case was oppening until the date when it was closed.

Is there any "easy" way to get that?

 

Thank you very much.

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    What Microsoft Dynamics product are you using?

  • Ricardo Caldas Profile Picture
    165 on at

    Hi Nick,

    Sorry, I'm new here. :)

    I'm using CRM 2011, thank you.

  • Community Member Profile Picture
    on at

    No worries!  I have moved your question to the CRM forum to help get this in front of more CRM users.

    Please let me know if you have any questions.

  • Verified answer
    Ricardo Caldas Profile Picture
    165 on at

    I found an workaround for my purpose.

    First of all, I found that java script only can reach fields that are on the form's body.
    I create a new decimal field do receive the calculated time (new_calculatedtime).

    Than I made a script (that I found on the internet) to run in the onsave event, like this:

    function Form_onsave()
    {
    var ONE_HOUR = 1000 * 60 * 60;
    var BeginDate = Xrm.Page.getAttribute("createdon").getValue();
    var ModifiedDate = Xrm.Page.getAttribute("modifiedon").getValue();

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(ModifiedDate - BeginDate );

    // Convert back to days and return
    Xrm.Page.getAttribute("new_calculatedtime").setValue(difference_ms/ONE_HOUR);
    }

    This returns you the time in hours, for the time in days use: var ONE_HOUR = 1000 * 60 * 60 * 24;

    Then I realized that if I add the field "new_calculatedtime" in the form's body, in read only mode, the data was not saved in the DB, so I need to block using another method.

    We created a script to run in thr onload event, that blocks me the field:

    function Form_onload()
    {
    var obj = document.getElementById("new_calculatedtime");
    obj.setAttribute("readOnly", "readonly");
    }

    This way, the calculatedtime is updated every time you save the case, but, after you close the case, it's no possible to you to save it again. So for me that is enough.
    I'm now able to create reports using this field and filtering the items by the statecode.

    Now I can made

    So, it is not the perfect solution, it would be better programming the form in the server side, but for me it's enough.

    I hope it helps someone
  • kanatamike Profile Picture
    120 on at

    Be careful relying on the "modified on" date.  There are system processes that run that can modify the case thereby changing this date even after a case has been closed.  I ran into this problem in the past.  Instead, it's better to create a custom field for the resolved on date.  You can populate it using with Javascript or a workflow that fires when the case status changes to resolved.  You can then pull the date from this field to do your calculation.

  • Suggested answer
    Eber Profile Picture
    165 on at

    Hi Ricardo,

    Sadly there is no easy way. You should create a field and a C# or JavaScript to add in the field the duration time.

    There is a good code tutorial how to do that on CRM ParkingLot blog: crm.ipiyush.me/calculate-duration-fields-in-dynamics-crm-2011-via-code-javascript-and-c

    Best regards,

    Éber Gustavo

  • Shh Profile Picture
    on at

    When you resolve a case, there are an activity record created backend by CRM system called "case resolution". You can get your actual case resolution date from there.

    If your case record been resolve and de-activate for a few time, then there are multiple record store in this "Case resolution" entity, which the previous resolve will mark as "Cancelled" by System.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans