Выполнение запроса caml для получения поля поиска: «Не удается выполнить это действие. Пожалуйста, попробуйте еще раз.»? - PullRequest
0 голосов
/ 20 января 2020

Это мой код запроса caml, чтобы получить значение поля поиска в SharePoint 2016 локально (CSOM).

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

попытался удалить эту часть "LookupId = 'TRUE" ", но все равно получить это исключение: «Не удается выполнить это действие. Пожалуйста, попробуйте еще раз». Я запускаю этот caml-запрос в U2U caml построителе запросов, но он работает.

1 Ответ

0 голосов
/ 21 января 2020

Протестировано CAML в CSOM, как показано ниже, работает:

        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);

            }
        }

Это данные списка тестов: enter image description here

enter image description here

...