1

It is my caml query code to get the value of a lookup field in SharePoint 2016 on-premises (CSOM).

<View>
                                <Query>
                                    <Where>
                                        <Eq>
                                            <FieldRef Name='myLookupField' LookupId='TRUE'/>
                                            <Value Type='Lookup'>18456</Value>
                                        </Eq>
                                    </Where>
                                </Query>
                            </View>

tried removing this part "LookupId='TRUE'" but still get this exception: "Cannot complete this action. Please try again." I run this caml query in U2U caml query builder but it works.

Squti
  • 4,171
  • 3
  • 10
  • 21

1 Answers1

2

Tested CAML in CSOM like below, it's working:

        using (ClientContext ctx=new ClientContext("http://sp/sites/dev/"))
        {
            List list = ctx.Web.Lists.GetByTitle("MyList22");
            CamlQuery caml = new CamlQuery();
            caml.ViewXml = "<View><Query><Where><Eq><FieldRef Name='myLookupField' LookupId='TRUE'/><Value Type='Lookup'>1</Value></Eq></Where></Query></View>";
            ListItemCollection items = list.GetItems(caml);
            ctx.Load(items);
            ctx.ExecuteQuery();
            foreach (ListItem item in items)
            {
                FieldLookupValue value = item["myLookupField"] as FieldLookupValue;
                Console.WriteLine("LookupId: "+ value.LookupId);
                Console.WriteLine("LookupValue: "+ value.LookupValue);

            }
        }

This is the test list data: enter image description here

enter image description here

Jerry
  • 3,480
  • 1
  • 10
  • 12