Hi y'all,
So I am attempting to get a Subgrid on a custom entity to dynamically display all activities where any contact related to the custom entity is a party to said activities.
I can get the data I need using advanced find, here is the FetchXML:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
<entity name="activitypointer" >
<attribute name="activitytypecode" />
<attribute name="subject" />
<attribute name="statecode" />
<attribute name="prioritycode" />
<attribute name="modifiedon" />
<attribute name="activityid" />
<attribute name="instancetypecode" />
<attribute name="community" />
<order attribute="modifiedon" descending="false" />
<link-entity name="activityparty" from="activityid" to="activityid" link-type="inner" alias="af" >
<link-entity name="contact" from="contactid" to="partyid" link-type="inner" alias="ag" >
<filter type="and" >
<condition attribute="customentity" operator="eq" uiname="name" uitype="customentity" value="{redacted}" />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
But of course, this only displays the activities for the hard coded contacts.
I eventually found the following Javascript and have been testing it to no avail. Can someone please take a quick look and tell me what I am doing wrong?
function filterSubGrid() {
var householdsGrid = document.getElementById("hhactivities"); //grid to filter
if (householdsGrid == null) { //make sure the grid has loaded
setTimeout(function () { filterSubGrid(); }, 2000); //if the grid hasn’t loaded run this again when it has
return;
}
var householdValue = Xrm.Page.data.entity.getId(); //field to filter by
var householdId = "00000000-0000-0000-0000-000000000000"; //if filter field is null display nothing
if (householdValue != null) {
var householdId = householdValue[0].id;
}
//fetch xml code which will retrieve all the activities related to all contacts in the household
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
" <entity name='activitypointer'>" +
" <attribute name='activitytypecode' />" +
" <attribute name='subject' />" +
" <attribute name='statecode' />" +
" <attribute name='prioritycode' />" +
" <attribute name='modifiedon' />" +
" <attribute name='activityid' />" +
" <attribute name='actualend' />" +
" <attribute name='instancetypecode' />" +
" <attribute name='community' />" +
" <order attribute='actualend' descending='false' />" +
" <link-entity name='activityparty' from='activityid' to='activityid' link-type='inner' alias='aa' >" +
" <link-entity name='contact' from='contactid' to='partyid' link-type='inner' alias='ab' >" +
" <filter type='and'>" +
" <condition attribute='customentity' operator='eq' uitype='customentity' value='" + householdId + "' />" +
" </filter>" +
" </link-entity>" +
" </link-entity>" +
" </entity>" +
"</fetch>";
householdsGrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
householdsGrid.control.refresh(); //refresh the sub grid using the new fetch xml
}
Thanks in advance for any insight
*This post is locked for comments
I have the same question (0)