My requirement is to pull external data to InfoPath form based on a filter (e.g. Name filter) to Acheive this I did below things (I am working on InfoPath 2010, SP 2010)

I have created a BCS to pull data from external sources and I placed a filter to filter the data based on one column (let’s say Name) Here my problem is when I add external list for above External Content Type it is not displaying any data, because the Name filter always sending as null hence no match was found. For me that should work as I specified above.

But when I try to query the external list from InfoPath form, I was unable to send the filter so it is always returning 0 rows.

I even used "External Item Picker" to pull the data, at this point I am able to filter the data but I am unable to get all other column values (There other columns in ECT like Status, Address etc) it is only checking for existence of the entered value which is not enough in my case.

Please suggest me a solution to complete my task

Thanks, Vasu.

  • Where and how will I write the above code? can you please elaborate.
    – user19690
    Commented Sep 22, 2013 at 16:04
  • Hi Usama, Please try to elaborate your requirement and then I can help you to get the solution Commented Sep 26, 2013 at 14:23

1 Answer 1


Finally I found a way to achive solution for above question (It can be helpful to others who are looking for same scenario)

  1. Create a external list for External Content Type in your site
  2. Query the external list from infopath (using coding and CAML Query)
  3. Before quering the list access the default view and modify the filter value.

look at below code for your reference

        SPWeb web = SPContext.Current.Web;
        string xpath = " /my:myFields/my:txtSearch";
        XPathNavigator txtSearch = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);
        string val = txtSearch.Value;
        SPList list = web.Lists["YOUR EXTRENAL LIST NAME OR ID"];
        SPView view = list.Views[0];
        view.Method = @"<Method Name=""ReadList""><Filter Name=""IdFilter"" Value=""" + val + @""" /></Method>";
        SPQuery spQuery = new SPQuery(view);
        string query = @"<View>
                                        <FieldRef Name=""Id""/>
                                    <FieldRef Name=""Id"" />
                                    <FieldRef Name=""Name""/>
                                    <FieldRef Name=""Username""/>
                                    <FieldRef Name=""Address""/>

        spQuery.Query = query;
        SPListItemCollection items = list.GetItems(spQuery);

in the above code "idFilter" is my filter name in the BCS.

Hope it helps you.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.