列表项的 Sharepoint 过滤器 (GetListItems) [英] Sharepoint Filter for List Items(GetListItems)

查看:46
本文介绍了列表项的 Sharepoint 过滤器 (GetListItems)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 WebService 从 sharepoint 获取一组列表项.我想查询要返回的一小部分项目.我的 SOAP 数据包似乎已正确排序,但是,该服务似乎仍然忽略了我设置的过滤器(查询).任何想法为什么仍然会发生这种情况?

I'm attempting to get a set of list items from sharepoint via the WebService. I want to query a small subset of items to be returned. My SOAP packet appears to be ordered properly, however, it still appears that the service is ignoring my set filter(query). Any ideas why this would still be happening?

<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns0:Body>
  <ns1:GetListItems>
     <ns1:listName>MyCalendar</ns1:listName>
     <query>
        <Query>
           <Where>
              <Eq>
                 <FieldRef Name="EventDate"/>
                 <Value Type="DateTime">[Now+2Minute(s)]</Value>
              </Eq>
           </Where>
        </Query>
     </query>
  </ns1:GetListItems>
</ns0:Body>
</SOAP-ENV:Envelope>

这是我用来生成这个肥皂的 python suds 代码:

and here is the python suds code that i used to generate this soap:

Query = Element('Query')
where = Element('Where')
eq = Element('Eq')
eq.append(Element('FieldRef').append(Attribute('Name', 'EventDate')))
vt = Element('Value').append(Attribute('Type', 'DateTime')).setText('[Now+2Minute(s)]')
eq.append(vt)
where.append(eq)
Query.append(where)

query = Element('query')
query.append(Query)

这是最终对我有用的合适的肥皂包和泡沫代码.我对过滤器有一些奇怪的要求,但我会继续按原样发布,以便其他人可以从中学习.

Here is the proper soap packet and suds code for what eventually worked for me. I have some strange requirements around the filter, but i'll go ahead and post as is so that others may learn from this.

<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns0:Body>
  <ns1:GetListItems>
     <ns1:listName>Economic Event Calendar</ns1:listName>
     <ns1:query>
        <Query>
           <Where>
              <And>
                 <Geq>
                    <FieldRef Name="EventDate"/>
                    <Value IncludeTimeValue="TRUE" Type="DateTime">2010-08-12T07:38:00</Value>
                 </Geq>
                 <Lt>
                    <FieldRef Name="EventDate"/>
                    <Value IncludeTimeValue="TRUE" Type="DateTime">2010-08-12T07:39:00</Value>
                 </Lt>
              </And>
           </Where>
        </Query>
     </ns1:query>
     <ns1:rowLimit>5</ns1:rowLimit>
     <viewFields>
        <FieldRef Name="Description"/>
        <FieldRef Name="EventDate"/>
     </viewFields>
  </ns1:GetListItems>
</ns0:Body>
</SOAP-ENV:Envelope>

以及让我来到这里的 python/suds 代码:

and the python/suds code that got me here:

#craft our XML
Query = Element('Query')
where = Element('Where')
And = Element('And')

geq = Element('Geq')
geq.append(Element('FieldRef').append(Attribute('Name', 'EventDate')))
vt = Element('Value').append(Attribute('IncludeTimeValue', 'TRUE'))
vt.append(Attribute('Type', 'DateTime')).setText(convert_dt('now +' + str(alertBefore) + ' minutes', '%Y-%m-%dT%H:%M:00' ))

lt = Element('Lt')
lt.append(Element('FieldRef').append(Attribute('Name', 'EventDate')))
vt2 = Element('Value').append(Attribute('IncludeTimeValue', 'TRUE'))
vt2.append(Attribute('Type', 'DateTime')).setText(convert_dt('now +' + str((alertBefore + 1))  + ' minutes', '%Y-%m-%dT%H:%M:00' ))

#viewFields fragment, only show the Description and EventDate for returned rows
viewFields = Element('viewFields')
viewFields.append(Element('FieldRef').append(Attribute('Name','Description')))
viewFields.append(Element('FieldRef').append(Attribute('Name','EventDate')))

#pack all the XML fragments
geq.append(vt)
lt.append(vt2)
where.append(And)
And.append(geq)
And.append(lt)
Query.append(where)
query = Element('ns1:query')
query.append(Query)

#issue the query
results = c_lists.service.GetListItems(SPCal, None, query, None, 5, viewFields, None)

推荐答案

尝试在 Value 元素上使用 IncludeTimeValue 属性:

Try using the IncludeTimeValue attribute on your Value element:

<Value Type="DateTime" IncludeTimeValue="TRUE">[Now+2Minute(s)]</Value>

根据 MSDN:

IncludeTimeValue:可选布尔值.指定基于时间和日期构建 DateTime 查询.如果不设置此属性,则查询中涉及日期和时间的时间部分将被忽略.

IncludeTimeValue: Optional Boolean. Specifies to build DateTime queries based on time as well as date. If you do not set this attribute, the time portion of queries that involve date and time are ignored.

我在 CAML 查询中没有使用很多 DateTime 过滤器,但关于 SOAP 数据包的其他所有内容看起来都是正确的.

I haven't used a lot of DateTime filters in my CAML queries, but everything else about your SOAP packet looks correct.

这篇关于列表项的 Sharepoint 过滤器 (GetListItems)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆