0

I have a CAML query which retrieves data from a SharePoint list. It passes for 1 input, but fails when there are 2 or more.

Error:

Microsoft.SharePoint.SPException: One or more field types are not installed properly. Go to the list settings page to delete these fields. ---> System.Runtime.InteropServices.COMException: One or more field types are not installed properly. Go to the list settings page to delete these fields.


After researching, probable cause may be due to mismatch SharePoint column InternalName . However, query managed to execute for 1 input, but not 2 or more.

Base on the query examples below, am I having a wrong format for the FAIL cases?


1. PASS:

<Where>
    <And>
        <Eq>
            <FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
        </Eq>
        <Neq>
            <FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
        </Neq>
    </And>
</Where>

2. FAIL:

<Where>
    <And>
        <Eq>
            <And>
                <Or>
                    <Eq>
                        <FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
                    </Eq>
                    <Eq>
                        <FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value>
                    </Eq>
                </Or>
                    <Neq>
                        <FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
                    </Neq>
            </And>
        </Eq>
    </And>
</Where>

3. FAIL:

<Where>
    <And>
        <Eq>
            <And>
                <Or>
                    <FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
                    <FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value>
                </Or>
                <Neq>
                    <FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
                </Neq>
            </And>
        </Eq>
        <Neq>
            <FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
        </Neq>
    </And>
</Where>
1

First of all check the internal names and data types of your fields you are using in your CAML query, Accordingly your queries will change.

If all your internal names are correct then try using below queries:

<Where>
    <And>
        <Or>
            <Eq>
                <FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
            </Eq>
            <Eq>
                <FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value>
            </Eq>
        </Or>
        <Neq>
            <FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
        </Neq>
    </And>
</Where>

This will return the results when:

Header1Ref is equal to "H1" or "H2" AND ContentType is not be equal to "Document".

official documentation: Query Schema.

Update:

If you are using OOTB ContentType field then you need to query on it like below:

  1. Using Content Type Name:
<Neq>
    <FieldRef Name="ContentType"/><Value Type="Computed">Document</Value>
</Neq>
  1. Using Content Type ID:
<BeginsWith>
   <FieldRef Name="ContentTypeId"/><Value Type="ContentTypeId">YourContentTypeIdHere</Value>
</BeginsWith>
  • Hi @Ganesh, I have checked that the internal names are correct, and the query for just a single Header1Ref does returned result. This error occurred when there are more than one Header1Ref value. I executed the query that you provided but encountered the same error as well. – gymcode Dec 13 '19 at 7:46
  • Are you using OOTB Content Type field or you have created a custom field for content type? – Ganesh Sanap Dec 13 '19 at 7:47
  • Also, is the data type of Header1Ref is single lines of text? – Ganesh Sanap Dec 13 '19 at 7:48
  • @gymcode Have you tried this? Is it working for you?? – Ganesh Sanap Dec 18 '19 at 5:33
0

2. Try:

<Where>
    <And>
        <And>
            <Or>
                <Eq>
                    <FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
                </Eq>
                <Eq>
                    <FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value>
                </Eq>
            </Or>
            <Neq>
                <FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
            </Neq>
        </And>
    </And>
</Where>

3. Try:

<Where>
    <And>
        <And>
            <Or>
                <Eq>
                    <FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
                </Eq>
                <Eq>
                    <FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value>
                </Eq>
            </Or>
            <Neq>
                <FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
            </Neq>
        </And> 
        <Neq>
            <FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
        </Neq>
    </And>
</Where>
0

In both number 2 and 3 you have And operators that only contain one test. It can be helpful to replace your tests with boolean values to better see how the queries will behave. Example for number 2:

Where
  And
    And         
      (True or True)
      False

The second And says that Header1Ref should be equal to either "H1" or "H2", and ContentType should not be equal to "Document".

The first And compares the result of the second And and nothing else. This is why it fails.

In number 3 you are also missing comparison operators inside your Or statement.

I think the following query will achieve what you are trying to do:

<Where>
    <And>
        <Or>
            <Eq>
                <FieldRef Name="Header1Ref"/><Value Type="Text">H1</Value>
            </Eq>
            <Eq>
                <FieldRef Name="Header1Ref"/><Value Type="Text">H2</Value>
            </Eq>
        </Or>
        <Neq>
            <FieldRef Name ="ContentType"/><Value Type="Text">Document</Value>
        </Neq>
    </And>
</Where>

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.