0

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.

3N1GM4
  • 3,372
  • 3
  • 19
  • 40
  • It is unsupported to set the view used in a subgrid from JS. Why are you not creating a system view and selecting that in the UI (with related records filtering)? – Henrik H Mar 14 '16 at 15:39
  • That is what I originally tried to do, but was unable to get the Only Related Records filtering to work as I wished (so that the results included any where the Contact had participation in the Activity of any kind), it would only show records where the Contact was the Regarding on the Activity - if there is a way to achieve this through the UI as you described, please let me know how! – 3N1GM4 Mar 15 '16 at 09:08
  • I see. One way is to point out to your users that this is shown in the Associated Activities view. Alternatively, if you want the information directly on the form, how about using the Social Pane (and e.g. defaulting it to show activities)? As far as I know, there is no supported way of getting equivalent information in a subgrid. Microsoft are aware of this: http://www.dynamicscrmpros.com/microsoft-dynamics-crm-2011-activity-sub-grids-only-display-regarded-records/ – Henrik H Mar 15 '16 at 12:15
  • Also see the following suggestion on Connect: https://connect.microsoft.com/dynamicssuggestions/feedback/details/670284/ability-for-sub-grid-activity-in-account-form-to-show-all-related-activities – Henrik H Mar 15 '16 at 12:15
  • Yes, I see that the All Activity Associated View does return all of the relevant records, which we have already communicated as a possible workaround, but we really do want these Activities to show on the Contact page itself. We cannot use the Social Pane as there are additional (custom) Activity Fields which we wish to display and as far as I am aware, we cannot customise the Social Pane to show these. It just seems odd to me that I am able to get the correct records to return and behave as desired using this fetchXML solution, but just cannot get the subgrid to refresh every time... – 3N1GM4 Mar 15 '16 at 13:12
  • Should I be able to access that connect.microsoft.com link from any Microsoft account? I'm getting a Page Not Found currently. – 3N1GM4 Mar 15 '16 at 13:23
  • I unfortunately do not have input on your above code and will let someone else weigh in. You need to log in to access Connect: http://www.crmanswers.net/2014/02/how-to-use-microsoft-connect-site.html – Henrik H Mar 15 '16 at 13:33

0 Answers0