Calculate difference between Actual Start & Actual End in Minutes

Task: Calculate difference between Actual Start Date & Actual End Date in minutes and Setvalue in Duration field onSave of Phone Call entity

Solution: Follow the below steps,

Step 1: Create Javascript Webresource “new_phoneCallJscript”. Copy and paste the below code in Javascript Webresource,

Step 2: Call the function calculateDurationinMinutes onSave of phonecall entity

function calculateDurationinMinutes() {
var actualStartObj = Xrm.Page.getAttribute("actualstart");
var actualEndObj = Xrm.Page.getAttribute("actualend");
var durationinMinutesObj = Xrm.Page.getAttribute("actualdurationminutes");
    if (actualStartObj != null && actualEndObj != null && durationinMinutesObj != null) {
       var actualStart = actualStartObj.getValue();
       var actualEnd = actualEndObj.getValue();
         if (actualStart != null && actualEnd != null) {
            var dateDifference = Math.abs(actualEnd - actualStart);
            var durationInMinutes = Math.floor((dateDifference / 1000) / 60);

Step 3: Save and Publish the Phone Call Activity. Open any Phone Call record and Select the value Actual Start and Actual End and click on Save to see the result in Duration field.

Please provide your valuable feedback on this article.