Hi Rocker,
Please help me find the bug.Debugging seems not to be helping.Following code working absolutely fine when i pack it in a JS file and run on form onload for ex.but there is an html file in my default solution.I m in need to embed this code there because i want to calculate this on click of a button :
function NextPlannedCallOnload() {
var currentAccount=window.parent.Xrm.Page.getAttribute("name").getValue();
var d = new Date();
var DateJour=new Date(d.getFullYear(),d.getMonth(),d.getDate(), 0, 0, 0, 0);
var frmatedDateJour = DateJour.format('yyyy-MM-dd');
if (currentAccount != null) {
var currentAccountId = window.parent.Xrm.Page.data.entity.getId();
}
var callPlanFetchXML="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
" <entity name='appointment'>"+
" <attribute name='subject' />"+
" <attribute name='statecode' />"+
" <attribute name='scheduledstart' />"+
" <attribute name='ownerid' />"+
" <attribute name='scheduledend' />"+
" <attribute name='createdon' />"+
" <attribute name='activityid' />"+
" <attribute name='regardingobjectid' />"+
" <order attribute='regardingobjectid' descending='false' />"+
" <order attribute='scheduledstart' descending='false' />"+
" <filter type='and'>"+
" <condition attribute='scheduledstart' operator='next-x-years' value='1' />"+
" <condition attribute='statecode' value='3' operator='eq'/> "+
" <condition attribute='scheduledstart' operator='on-or-after' value='"+currentAccountId+"'/>"+
" <condition attribute='regardingobjectid' operator='eq' value='"+frmatedDateJour+"'/>"+
" </filter>"+
" </entity>"+
"</fetch>";
var callPlanRecords = XrmServiceToolkit.Soap.Fetch(callPlanFetchXML);
if (callPlanRecords.length == 0)
Xrm.Page.getAttribute("new_nextplannedcall").setValue(" ");
if (callPlanRecords.length >0) {
if (callPlanRecords[0].attributes.scheduledstart != undefined || callPlanRecords[0].attributes.scheduledstart != null)
{
var NxtAppDate=callPlanRecords[0].attributes.scheduledstart.value;
Xrm.Page.getAttribute("new_nextplannedcall").setSubmitMode("always");
Xrm.Page.getAttribute("new_nextplannedcall").setValue(NxtAppDate);
}
}
}
Let me know if any input needed from my end.