python - 列表项的 Sharepoint 过滤器 (GetListItems)

标签 python sharepoint soap

我正在尝试通过 Web 服务从共享点获取一组列表项。我想查询一小部分要返回的项目。我的 SOAP 数据包似乎排序正确,但是,该服务似乎仍然忽略了我设置的过滤器(查询)。知道为什么这仍然会发生吗?

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

这里是我用来生成这个 soap 的 python suds 代码:

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)

编辑:

这是最终对我有用的正确 SOAP 包和 SOAP 水代码。我对过滤器有一些奇怪的要求,但我会继续并按原样发布,以便其他人可以从中学习。

<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 代码:

#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 属性:

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

根据 MSDN :

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 数据包的其他一切看起来都是正确的。

关于python - 列表项的 Sharepoint 过滤器 (GetListItems),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3449039/

相关文章:

javascript - 如何确保我的 javascript 函数仅在加载所有外部 javascript 后执行?

sharepoint - 功能事件处理程序为农场级功能多次调用 - sharepoint 2007

java - 加载时出错 [http ://localhost:8888/testWS]: java. lang.Exception : Failed to load url; http://localhost:8888/testWS, 0

java - 使用 XML 参数 UTF-8 Java 发送 SOAP 请求

python - 模拟标准输入 - python 3中的多行

python - 了解 Pyramid 中的资源和上下文

python - swig shared_ptr 导致不透明对象

javascript - var 查询未返回所需结果

javascript - BaseHTTPRequestHandler doPOST方法不更新html?

java - 使用 Apache CXF 调用 SOAP API 时发生 ClassCastException