Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Filtering subgrid from lookup value

$
0
0

Hello Everyone, 

I have set up a N:N relationship between a custom entity and the contacts entity. I have been trying to create some code that would filter the subgrid on the custom entity to only show contacts that relate to another lookup field on the custom entity that is the parent account of the contacts. I have used the advanced find to generate the fetchXml code as I have read/seen examples showing how to do that. When I set the code as an onchange function the subgrid does not filter to only related contacts of the parent company. 

I have included the code I have been using below. I think some of where the hang up might be is in the conditioning lines. I'm not sure I am using the right field names in the right places. 

Any help is greatly appreciated. 

Thank you!

function subgrid() {

	var relatedContacts = document.getElementById("new_new_siteenvironment_contact");
	var schooldistrict = Xrm.Page.getAttribute("new_schooldistrict").getValue();

	if (schooldistrict != null) {
		
		var schooldistrictid = schooldistrict[0].id;
		var schooldistrictname = schooldistrict[0].name;
	}
	else {
		return;
	}
	
	if((relatedContacts == null) || (relatedContacts.readyState != "complete")) {
		setTimeout('subgrid()', 2000);
		return;
	}

	var fetchXml = "<?xml version='1.0'?>";
	fetchXml += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
	fetchXml += "<entity name='new_siteenvironment' />"; 
	fetchXml += "<attribute name='new_siteenvironmentid' />";
        fetchXml += "<attribute name='new_name' />";
	fetchXml += "<attribute name='createdon' />";
	fetchXml += "<order attribute='false' attribute='new_name' />";
	fetchXml += "<link-entity name='account' alias='aa' to='new_schooldistrict' from='accountid' >";
        fetchXml += "<link-entity name='contact' alias='ab' to='accountid' from='parentcustomerid' />";
        fetchXml += "<filter type='and'>";
	fetchXml += "<condition attribute='new_siteenvironment' operator='eq' uiname='" + schooldistrictname + "' uitype='new_siteenvironment' value='" + schooldistrictid + "' />";
        fetchXml += "</condition>";
        fetchXml += "</filter>";
	fetchXml += "</link-entity>";
        fetchXml += "</entity>";
	fetchXml += "</fetch>";
	relatedContacts.control.setParameter("fetchXml", fetchXml);
	relatedContacts.control.Refresh();
}


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>