2010-08-10 89 views
2

我試圖通過WebService從sharepoint獲取一組列表項。我想查詢一小部分要返回的項目。我的SOAP數據包似乎是正確排序的,但是,它仍然顯示服務忽略了我的設置過濾器(查詢)。任何想法爲什麼這仍然會發生?列表項的Sharepoint篩選器(GetListItems)

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

,這裏是蟒蛇泡沫代碼,我用來生成這種肥皂:

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

和蟒蛇/泡的代碼,讓我在這裏:

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

回答

1

嘗試使用Value元素的IncludeTimeValue屬性:

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

根據MSDN

IncludeTimeValue:可選布爾值。指定基於時間和日期構建DateTime查詢。如果您未設置此屬性,則會忽略涉及日期和時間的查詢的時間部分。

我的CAML查詢中沒有使用很多DateTime過濾器,但其他所有有關SOAP包的內容看起來都正確。

+0

CBono,你是先生!在我發佈它幾個小時後,我發現了這個問題。 U2U的CAML Generator確實幫助我解決了這個問題。感謝您的答覆! – nnachefski 2010-08-12 12:45:46

+1

是的,CAML Builder是SP開發人員必備的工具。 – CBono 2010-08-12 13:07:18