MSCRM 2011: Filtering Cities based on State
Use the following code to filter and change the Entity names according to your requirement.
function onstateChange()
{
var stateAttr = Xrm.Page.data.entity.attributes.get("new_state");
if (stateAttr.getValue() != null)
{
var stateID = stateAttr.getValue()[0].id;
var viewID = stateID;
var viewDisplayName = "Filtered by state - " + stateAttr.getValue()[0].name;
var viewIsDefault = true;
var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="new_city"><attribute name="new_cityid"/><attribute name="new_name"/><attribute name="createdon"/><order attribute="new_name" descending="false"/><filter type="and"><condition attribute="new_state" operator="eq" value="' + stateID + '"/></filter></entity></fetch>';
var layoutXml = '<grid name="resultset" object="10001" jump="new_name" select="1" icon="1" preview="1"><row name="result" id="new_cityid"><cell name="new_name" width="300" /><cell name="createdon" width="125"/></row></grid>';
var phaseControl = Xrm.Page.ui.controls.get("new_city");
phaseControl.addCustomView(viewID, "new_city", viewDisplayName, fetchXml, layoutXml, viewIsDefault);
}
}
Hope this will help :)
Best Regards,
Sreenath