Help with FilteredLookup

Aug 28, 2012 at 12:28 PM


Your control is very nice, it has helped me a lot but now I need to Filter your lookup control and I am struggling with a very tight deadline to deliver a project.

I am new to silverlight technologies so I am not understanding without a sample for FilteredLookup.

I have a MainPage.xaml from where I call your lookup control but I need to filter that lookup from another dependant lookup. In my scenario I need to filter Account and Contact records based on the related Project entity records. Following is the code that I am using.


<my:SilverCrmLookup Height="22" HorizontalAlignment="Left" Margin="0,0,0,0" Name="lkpClientAttendees" VerticalAlignment="Center" Width="665" EntityName="account" Icon="/MySilverlightApp1;component/Images/ico_16_2.png" LookupStyle="Multi" ShowNewButton="False" ShowPropButton="False" Loaded="lkpClientAttendees_Loaded"/>


        private void lkpClientAttendees_Loaded(object sender, RoutedEventArgs e)
            StringBuilder sb = new StringBuilder();
            sb.Append("<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>");
            sb.Append("<entity name='account'>");
            sb.Append("<attribute name='name' />");
            sb.Append("<attribute name='address1_city' />");
            sb.Append("<attribute name='primarycontactid' />");
            sb.Append("<attribute name='telephone1' />");
            sb.Append("<attribute name='ts_interestedinacquisitions' />");
            sb.Append("<attribute name='ts_availableforprospectapproach' />");
            sb.Append("<attribute name='ts_availableformarketing' />");
            sb.Append("<attribute name='accountid' />");
            sb.Append("<order attribute='name' descending='false' />");
            sb.Append("<filter type='and'>");
            sb.Append("<condition attribute='statecode' operator='eq' value='0' />");
            sb.Append("<link-entity name='contact' from='contactid' to='primarycontactid' visible='false' link-type='outer' alias='accountprimarycontactidcontactcontactid'>");
            sb.Append("<attribute name='emailaddress1' />");
            sb.Append("<link-entity name='ts_project' from='ts_primaryclientid' to='accountid' alias='aa'>");
            sb.Append("<filter type='and'>");
            sb.Append("<condition attribute='ts_projectid' operator='eq' uiname='Sell Touchstone' uitype='ts_project' value='{1805548A-07DB-E111-BBE6-0050569C00D3}' />");
            StringBuilder sb1 = new StringBuilder();
            sb1.Append("<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>");
            sb1.Append("<row name='result' id='accountid'>");
            sb1.Append("<cell name='name' width='300' />");
            sb1.Append("<cell name='telephone1' width='100' />");
            sb1.Append("<cell name='address1_city' width='100' />");
            sb1.Append("<cell name='primarycontactid' width='150' />");
            sb1.Append("<cell name='accountprimarycontactidcontactcontactid.emailaddress1' width='150' disableSorting='1' />");
            sb1.Append("<cell name='ts_availableformarketing' width='150' />");
            sb1.Append("<cell name='ts_availableforprospectapproach' width='150' />");
            sb1.Append("<cell name='ts_interestedinacquisitions' width='150' />");

            lkpClientAttendees.FilteredView = new LookupControl.LookupView() { DisplayName = "Filtered Client Attendees", FetchXml = sb.ToString(), LayoutXml = sb1.ToString(), ObjectTypeCode = "1", ViewId = new Guid("00000000-0000-0000-00AA-000010001002") };

I have hardcoded the project id in above code but Ideally would like to populate the ProjectId at runtime.

You help will be high appreciated. Thank you in advance

Kind regards

Aug 28, 2012 at 8:46 PM
Edited Aug 28, 2012 at 8:49 PM


Glad to hear that the control helped you. I hope you already have a working filtered lookup but the problem you have is building the fetch xml with dynamic guid's

I suggest you to get the ts_projectid lookup value dynamically and if it has multiple values loop through the values and generate the fetch xml

sb.Append("<condition attribute='ts_projectid' operator='eq' uiname='Sell Touchstone' uitype='ts_project' value='"+ts_lookupid+"' />");
or if it is also a lookup control and a multi lookup
foreach (var item in ts_lookup.Items)
					values += "<value uitype='ts_lookup' >{" + item.Id.ToString() + "}</value>";
sb.Append("<condition attribute='ts_lookupidid' operator='in'>" +
						  values +
also the viewId
ViewId = Guid.NewGuid()

Aug 29, 2012 at 8:45 AM


Thank you very much for your reply back. My problem is not getting the id dynamically my problem is I have several lookup controls on a single silverlight xaml page.

I am building the FilteredLookup in code behind on Loaded event and loaded event fires when the silverlight application is loaded for the firsttime and at that stage my Project lookup is not populated yet.

Ideally I would like to fire something like LookupContentClick event so that I can build the dynamic FetchXML at the time when I click lookup button. Hope I explained my problem correctly.


Aug 30, 2012 at 11:43 AM
Edited Aug 30, 2012 at 11:50 AM

Hi Sam

sorry for the late reply. In this case you have to set the filter of the nested lookup on change of the previous lookup. just like filtering nested combo boxes. 

 there is an event for On Change. Its LookupOnValueChange