Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to retrieve the 5 most upcoming (with respect to expiry date) announcement list item "Title's".The query partly works but what it fails to do is include and display todays announcements as well (For ex: Announcements posted earlier in the morning).

I looked around the net and all of that suggests adding the IncludeTimeValue='TRUE' in the tag, but it still does not work. What am I missing? I have also tried using the <now/>.

Query

enter image description here

share|improve this question
    
This looks like it should work to me. I know this sounds like a stupid question, are you certain the data is there to supply the expected results? –  Robert Kaucher Mar 23 '12 at 15:58
add comment

3 Answers

up vote 3 down vote accepted

Unless you're sure that all the announcements you want has an Expire datetime then you're missing an "or+isnull" like this:

<Query>
 <Where>
  <And>
   <IsNotNull>
    <FieldRef Name="Title" />
   </IsNotNull>
   <Or>
    <IsNull>
     <FieldRef Name="Expires" />
    </IsNull>
    <Geq>
     <FieldRef Name="Expires" />
     <Value IncludeTimeValue="TRUE" Type="DateTime">
      <Today />
     </Value>
    </Geq>
   </Or>
  </And>
 </Where>
 <OrderBy>
  <FieldRef Name="Expires" Ascending="True" />
 </OrderBy>
</Query>

enter image description here

share|improve this answer
    
I tried adding the <or> content, but it would still not display todays announcements. I have put up a screenshot for reference. I tried the <Now/> tag as well and it wouldnt work. Please advise. –  user7400 Mar 23 '12 at 18:17
    
Interesting observation. I tried the same query to retrieve calendar (event list) items and it displays just fine with the <today/> function. However it still does not display items that have expired an hour ago, which is good. –  user7400 Mar 23 '12 at 19:16
add comment

Partly answered:

I just used the date and not the datetime. Since it was just announcements I didn't mind it being on the page for an extra day. The default expires field only holds the data value anyway. A simple <geq> on the Expires field with type="Date" did it for me.

share|improve this answer
add comment

I set up some announcements exactly like what you have in the screen shot. I did not get correct results in my view until I, for some reason, included the Expires field in the ViewFields element.

<View Name="{5613B6A8-3D6D-40B0-9597-8CDBD9DD92AC}" Type="HTML" DisplayName="TodayOrLater" Url="/teams/root/it/Lists/Announcements/TodayOrLater.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/announce.png">
                <Query>
                    <Where>
                        <And>
                            <IsNotNull>
                                <FieldRef Name="Title"/>
                            </IsNotNull>
                            <Geq>
                                <FieldRef Name="Expires"/>
                                <Value Type="DateTime">
                                    <Today/>
                                </Value>
                            </Geq>
                        </And>
                    </Where>
                </Query>
                <ViewFields>
                    <FieldRef Name="Attachments"/>
                    <FieldRef Name="LinkTitle"/>
                    <FieldRef Name="Modified"/>
                    <FieldRef Name="Expires"/>
                </ViewFields>
                <RowLimit Paged="TRUE">30</RowLimit>
                <Aggregations Value="Off"/>
                <Toolbar Type="Standard"/>
            </View>

enter image description here

share|improve this answer
    
Could you show me your outpu to get a better picture please. And the paged=true property you have used is interesting. UNfortunately I cannot use it my query as it does not work for some reason. I have to specify spQuery.Rowlimit=5; –  user7400 Mar 23 '12 at 19:14
    
Just to be clear, that is the View Definition inside of a custom view page. –  Robert Kaucher Mar 23 '12 at 19:29
    
Hmmm....Robert I am trying to create a visual web part. Take a look at my output (added to original question) to see if me using the <view> tag makes sense please. Thanks –  user7400 Mar 23 '12 at 20:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.