Forum Discussion

Frank Nielsen's avatar
Frank Nielsen
Copper Contributor
Nov 14, 2019
Solved

CAML Query with two conditions not working

Hi all. I am very new to CAML Quey in SharePoint, but I want to make a query in a highlighted content web part, with two conditions, and it is not working :(. If I only set one condition, then the results shows up fine, but two conditions, and nothing happens. This is my query:

 

<View>
<Query>
<OrderBy>
<FieldRef Name="Title"
Ascending="TRUE"></FieldRef>
</OrderBy>
<Where>
<And>
<BeginsWith><FieldRef Name="Title"></FieldRef><Value Type="Text">I-0</Value></BeginsWith>
<BeginsWith><FieldRef Name="Title"></FieldRef><Value Type="Text">I-1</Value></BeginsWith>
</And>
</Where>
</Query>
</View>

 

Can anyone guide mee in where I am doing something wrong? I have tried with the Or condition as well, but that did not help :(.

 

Hope some of you hard coders can figure this out.

THX in advance.

/Frank Nielsen, Denmark

  • Frank Nielsen 

     

    Hi Frank,

     

    Not sure which version of SharePoint you are usingQuery looks OK for me ,AND condition wont work.

    Make sure you use OR condition,However we can design the CAML Query using the UI Tools or google  with CAML Query Builder /CAML Designer

     

    here is the link

    https://www.biwug.be/resources

     

    I hope this works for Sharepoint online too,just check it.

6 Replies

  • O365Developer's avatar
    O365Developer
    Copper Contributor

    Frank Nielsen 

     

    Hi Frank,

     

    Not sure which version of SharePoint you are usingQuery looks OK for me ,AND condition wont work.

    Make sure you use OR condition,However we can design the CAML Query using the UI Tools or google  with CAML Query Builder /CAML Designer

     

    here is the link

    https://www.biwug.be/resources

     

    I hope this works for Sharepoint online too,just check it.

      • miler4199's avatar
        miler4199
        Copper Contributor

        Frank Nielsen 

        I have also been trying to get a CAML query functioning in SharePoint online.

        1. In addition to the CAML code, do you need any other code inserted into the web part to get the query to work?

        2. What web part are you using?  I see a "content query" web part as an option. Is this where you insert the code, and then it would apply to the list on that page?

         

        Thanks.

    • Frank Nielsen's avatar
      Frank Nielsen
      Copper Contributor

      O365Developer THX for quick reply. I am sorry I did not mention wich version of SharePoint I am using. It is SharePoint Online, and I was thinking that the highlitetd webpart in Sharepoint Online is not supporting two CAML conditions. I have seen a lot with SharePoint through the years, so I would not be surprised :cryingwithlaughter:

       

      I will try your suggestion and use the Or function instead.

       

      /Frank

Resources