0

I'm trying to get a CAML query working with dates - specifically PublishingStartDate and PublishingExpirationDate.

When scheduling an item, there is the option to select 'immediately' and 'never' for the start and end dates. My understanding of these options is that they create a null value instead of a date so I need to query for 'null or later than the start date' and also 'null or before the end date' if that makes sense.

I'm trying to use this in a query builder without much luck so any guidance in the right direction would be appreciated.

<Query>
<Where>
  <And>
     <And>
        <Or>
           <IsNull>
              <FieldRef Name='PublishingStartDate' />
           </IsNull>
        </Or>
        <Leq>
           <FieldRef Name='PublishingStartDate' />
           <Value Type='DateTime'>
              <Today OffsetDays='0' />
           </Value>
        </Leq>
     </And>
     <And>
        <Or>
           <IsNull>
              <FieldRef Name='PublishingExpirationDate' />
           </IsNull>
        </Or>
        <Geq>
           <FieldRef Name='PublishingExpirationDate' />
           <Value Type='DateTime'>
              <Today OffsetDays='0' />
           </Value>
        </Geq>
     </Or>
  </And>
</Where>
</Query>

1 Answer 1

1

Your OR and AND tags are not correct. They should wrap the two items being operated:

<Query>
  <Where>
       <And>
         <Or>
           <IsNull>
             <FieldRef Name='PublishingStartDate' />
           </IsNull>
           <Leq>
             <FieldRef Name='PublishingStartDate' />
             <Value Type='DateTime'>
               <Today OffsetDays='0' />
             </Value>
           </Leq>
         </Or>           
         <Or>
          <IsNull>
            <FieldRef Name='PublishingExpirationDate' />
          </IsNull>   
          <Geq>
            <FieldRef Name='PublishingExpirationDate' />
            <Value Type='DateTime'>
              <Today OffsetDays='0' />
            </Value>
         </Geq>
        </Or>
     </And>
  </Where>
</Query>
1
  • Thanks - I ended up just creating a new StartDate/EndDate column instead of using the OOTB scheduling feature which turned out to be incredibly easier than doing a QueryOverride.
    – Aaron
    Commented Feb 10, 2015 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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