0

I have Tests and Methods Lists.

Tests:

TestName

  • Test1

Methods: MethodName, TestName(look up wit

  • Method1, Test1

  • Method2, Test2

    TestName)

I want to filter methods with caml query by lookup value.

  var metodList = web.Lists["Methods"];

  query.Query = @"<Where><Eq><FieldRef Name='TestName'/>
                  <Value Type='Lookup'>Test1</Value></Eq></Where>";

       var metods = metodList.GetItems(query);

      foreach (SPListItem metodItem in metods.List.Items)
                    {
                        metodViewModelList.Add(new MetodViewModel
                        {
                            MetodId = Convert.ToInt32(metodItem["ID"]),
                            MetodName = metodItem["MethodName"].ToString()
                        });
                    }

But it isn't working. metods.List.items has two items. Method2 is coming too.

Where am i doing wrong?

Community
  • 1
  • 1
Erkan
  • 35
  • 1
  • 10

1 Answers1

0

Try:

string lkp_metod = metodItem["TestName"].ToString();
SPFieldLookupValue lkp_metod_value = new SPFieldLookupValue(lkp_metod);

MetodId = lkp_metod_value.LookupId.ToString();
MetodName = lkp_metod_value.LookupValue.ToString();
jpussacq
  • 573
  • 9
  • 29
  • 3
    I am not sure whether to delete your answer because of code only. But I recommend you to write some description how your answer will solve OP problem. – Ajay S Aug 13 '14 at 19:05
  • That is not my problem, I want to filter by look up item value. But caml query is not working. – Erkan Aug 15 '14 at 11:11
  • Mmm. I think you query is OK, but you can try creating the view with SharePoint, and then extract the caml schema using this approach: http://snahta.blogspot.com.ar/2011/03/getting-caml-query-from-existing-view.html This will help to find the error. – jpussacq Aug 15 '14 at 11:52