Archive | October, 2012

CAML Query cannot complete this action

11 Oct
  1. I was working on a SharePoint timer job, similar to many I have done before. The small difference was that the client I was working with had a complex list of states that an item might be in. So I had to specify multiple strings to look for in the underlying CAML query.
    So I took what would have been something like:<And><Eq><FieldRef Name=’Type’ /><Value Type=’Text’>ProcessItem</Value></Eq>
    <Eq><FieldRef Name=’Status’ /><Value Type=’Text’>Pending</Value></Eq>
    </And>
    and changed it to <Or><Eq><FieldRef Name=’Status’ /><Value Type=’Text’>Pending</Value></Eq>
    <Eq><FieldRef Name=’Status’ /><Value Type=’Text’>Processing</Value></Eq>
    <Eq><FieldRef Name=’Status’ /><Value Type=’Text’>Queued</Value></Eq>
    <Eq><FieldRef Name=’Status’ /><Value Type=’Text’>Transferring</Value></Eq>
    </Or>

    Which promptly failed.
    and the error was “Cannot complete this action”
    I figured I had tried to grab too many records and the query was timing out, so I tried a few things before consulting the web.
    Fortunately the fix was simple to do, well documented and easy to find.

  2. Yep that’s it. CAML cant deal with more than two criteria inside of an OR or AND clause.
    SMH
    so now my code looks like this:<Or><Or><Eq><FieldRef Name=’Status’ /><Value Type=’Text’>Pending</Value></Eq>
    <Eq><FieldRef Name=’Status’ /><Value Type=’Text’>Processing</Value></Eq>
    </Or><Or><Eq><FieldRef Name=’Status’ /><Value Type=’Text’>Queued</Value></Eq>
    <Eq><FieldRef Name=’Status’ /><Value Type=’Text’>Transferring</Value></Eq>
    </Or></Or>
    Lame, but there you have it.