Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
Where and how will I write the above code? can you please elaborate. –  user19690 Sep 22 '13 at 16:04
    
Hi Usama, Please try to elaborate your requirement and then I can help you to get the solution –  Vasu Ravuri Sep 26 '13 at 14:23
add comment

1 Answer 1

up vote 1 down vote accepted

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>
                                <Query>
                                    <OrderBy>
                                        <FieldRef Name=""Id""/>
                                    </OrderBy>
                                </Query>
                                <ViewFields>
                                    <FieldRef Name=""Id"" />
                                    <FieldRef Name=""Name""/>
                                    <FieldRef Name=""Username""/>
                                    <FieldRef Name=""Address""/>
                                </ViewFields>
                            </View>";

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

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

Hope it helps you.....

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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