问题
I have created a subgrid on a Form for the Contact Entity in Dynamics CRM 2015 which returns all Email, Task, Appointment and Phone Call Activities where either the Activity is Regarding the Contact for which the Form has been loaded, or where that Contact is a participant in the Activity (i.e. in the Sender or To/CC/BCC fields for an email, or on the attendee list for an Appointment).
I have added a new subgrid (called "NewActivities" for now) to my Contact Form which uses a specific Activity View which I have created (and is designed with criteria that will "never" return any results - DateCreated >= 01/01/2050) and then created a javascript function which I have included as a Web Resource in my Solution and am calling in the OnLoad event of the Form:
function DisplaySubGrid() {
var subgrid = document.getElementById("NewActivities");
if (subgrid == null) {
setTimeout('DisplaySubGrid()', 1000);
return;
}
var fetchXml =
"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>"
+ "<entity name='activitypointer'>"
+ "<attribute name='activityid' />"
+ "<attribute name='activitytypecode' />"
+ "<attribute name='subject' />"
+ "<attribute name='statecode' />"
+ "<attribute name='regardingobjectid' />"
+ "<attribute name='ownerid' />"
+ "<attribute name='scheduledend' />"
+ "<attribute name='createdby' />"
+ "<attribute name='createdon' />"
+ "<order attribute='scheduledend' descending='false' />"
+ "<order attribute='subject' descending='false' />"
+ "<filter>"
+ "<condition attribute='activitytypecode' operator='in'>"
+ "<value>4201</value>"
+ "<value>4202</value>"
+ "<value>4210</value>"
+ "<value>4212</value>"
+ "</condition>"
+ "</filter>"
+ "<link-entity name='activityparty' from='activityid' to='activityid' alias='ae'>"
+ "<filter>"
+ "<condition attribute='partyid' operator='eq' uiname='" + Xrm.Page.getAttribute("fullname").getValue() + "' uitype='contact' value='" + Xrm.Page.data.entity.getId() + "' />"
+ "</filter>"
+ "</link-entity>"
+ "</entity>"
+ "</fetch>"
subgrid.control.SetParameter("fetchXml", fetchXml);
subgrid.control.refresh();
}
Hopefully the above makes sense, I'm returning attributes which match those of the Activity View which is being used in the subgrid I've set up and then filtering for the Activity Types I want and just where the Activity Party is the Contact on the page. This is working fine except for one odd behaviour.
The problem is that sometimes when navigating to this Contact Form, the subgrid does not refresh - even though my javascript (including the subgrid.control.refresh()
call) is definitely running - and so the subgrid shows no Activity records. If I refresh the subgrid manually (right click -> Refresh List) after page load, the correct results are shown - I don't understand why this is happening. It seems to be when navigating away from the Contact Form and then using the Back in my browser to return, but I have also had it happen on a page refresh.
来源:https://stackoverflow.com/questions/35985079/subgrid-containing-activities-returned-by-fetchxml-query-not-always-refreshing