none
CAML Query Logic Operator with two Logic Operators RRS feed

  • Question

  • I have written a CAML query that contains an Or operand which contains two And operands, ensuring that no single logic operand contains more than two conditions.

    This CAML Query works great when placed in the aspx file. However, because the Sharepoint UI has no way to hand this query, whenever I make a change to the view using the SharePoint UI, The UI overrides my query.

    Here is my Query:

    <Where>
    	<Or>
    		<And>
    			<Geq>
    				<FieldRef Name="EventDate" />
    				<Value Type="DateTime"><Today OffsetDays="-1" /></Value>
    			</Geq>
    			<Leq>
    				<FieldRef Name="EventDate" />
    				<Value Type="DateTime"><Today OffsetDays="1" /></Value>
    			</Leq>
    		</And>
    		<And>
    			<Geq>
    				<FieldRef Name="EndDate" />
    				<Value Type="DateTime"><Today OffsetDays="-1" /></Value>
    			</Geq>
    			<Leq>
    				<FieldRef Name="EventDate" />
    				<Value Type="DateTime"><Today OffsetDays="1" /></Value>
    			</Leq>
    		</And>
    	</Or>
    </Where>

    The logic behind this query is:

    If I have an event that starts or ends Yesterday, Today or Tomorrow, I want to select it.

    If I have an event that stated in the past and ends in the future, I want to select it.

    Is there a way I can avoid the SharePoint UI overwriting my query, or is there a better way to write the query?

    Thank you!

    Wednesday, December 28, 2016 5:42 PM

Answers

  • Hi,

    We can use SharePoint UI to achieve your requirement.

    Start Time is greater than or equal to "[Today]-1"

    And

    Start Time is less than or equal to "[Today]+1"

    Or

    End Time(Indexed) is greater than or equal to "[Today]-1"

    And

    Start Time is less than or equal to "[Today]+1"

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by swalker1522 Thursday, December 29, 2016 1:34 PM
    Thursday, December 29, 2016 7:09 AM
    Moderator

All replies

  • Hi,

    We can use SharePoint UI to achieve your requirement.

    Start Time is greater than or equal to "[Today]-1"

    And

    Start Time is less than or equal to "[Today]+1"

    Or

    End Time(Indexed) is greater than or equal to "[Today]-1"

    And

    Start Time is less than or equal to "[Today]+1"

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by swalker1522 Thursday, December 29, 2016 1:34 PM
    Thursday, December 29, 2016 7:09 AM
    Moderator
  • Although this does not evaluate to the same query I was using, it evaluates to a query that passes the same truth table. I guess I should've looked at the truth table of the query SharePoint generated before assuming it was wrong.

    Thanks!

    Thursday, December 29, 2016 1:36 PM