function time()
{
var stdate = Xrm.Page.getAttribute("new_starttime").getValue();
var endate = Xrm.Page.getAttribute("new_finishtime").getValue();
if(stdate == null && endate == null)
{ alert(“Please enter the Start Time / Finish Time…”);
return false;
}
else if(stdate==null)
{ alert(“Please enter the Start Time !”);
return false;
}
else if(endate==null)
{ alert(“Please enter the Finish Time !”);
return false;
}
var st=stdate.getTime();
var ed=endate.getTime();
var sdiff=(ed-st);
var h=(sdiff/60/1000);
var p=parseInt(h);
var tm=p.toString();
Xrm.Page.getAttribute("new_timespent").setValue(tm);
}
Above code is for making two calculated fields Starting Date/time(when record is created) and Ending Date/time(current time of system). Then we make third different field which is Time Spent which is also calculated field. So, check the code for error free and if there are another way to make the calculated field send me link.
*This post is locked for comments
Thank you Rawish
And I am using Dyanmics 365 CRM Online(Trial version)
Hi Shakti,
What version of CRM do you have , did you try out of the box calculated field if available?
technet.microsoft.com/.../dn832103.aspx
otherwise , code is okay. run it & post error if you get any/.
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6