0

I have a dynamic CAML builder which I built to generate queries like the following:

<View Scope="RecursiveAll">
  <ViewFields>
    <FieldRef Name="Editor" />
    <FieldRef Name="Modified" />
  </ViewFields>
  <Query>
    <Where>
      <In>
        <FieldRef Name="Created" />
        <Values>
          <Value Type="DateTime">2015-08-15T00:00:00Z</Value>
          <Value Type="DateTime">2014-08-15T00:00:00Z</Value>
        </Values>
      </In>
    </Where>
  </Query>
</View>

I receive a "Value does not fall within the expected range" error. The query works when I change it to other field types like text, number, user, etc. It also works when I use this date format with an Eq element while querying the same field. Is there something I'm doing wrong here or is this element not supported for date fields?

0

The In elements primary function is to find IDs or text values in e.g. Lookup, Managed Metadata, User, and Choice fields.

You can not use it like you're trying to. For what you are trying to do, using an Or operator together with Eq would be adequate and preferred.

<Or>
    <Eq>
        <FieldRef Name="Created" />
        <Value Type="DateTime">2015-08-15T00:00:00Z</Value>
    </Eq>
    <Eq>
        <FieldRef Name="Created" />
        <Value Type="DateTime">2015-08-15T00:00:00Z</Value>
    </Eq>
</Or>

Or if you want to get all items that were created between 2 dates, then you should use Geq and Leq instead of Eq

<Or>
    <Geq>
        <FieldRef Name="Created" />
        <Value Type="DateTime">2015-08-15T00:00:00Z</Value>
    </Geq>
    <Leq>
        <FieldRef Name="Created" />
        <Value Type="DateTime">2015-08-15T00:00:00Z</Value>
    </Leq>
</Or>
  • I had this working, but I was just hoping the In element worked somehow. I'll make it generate this instead. Thanks! – Dinerdo Aug 18 '15 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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