SOLVED
Home

CAML Query with two conditions not working

%3CLINGO-SUB%20id%3D%22lingo-sub-1008486%22%20slang%3D%22en-US%22%3ECAML%20Query%20with%20two%20conditions%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1008486%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all.%20I%20am%20very%20new%20to%20CAML%20Quey%20in%20SharePoint%2C%20but%20I%20want%20to%20make%20a%20query%20in%20a%20highlighted%20content%20web%20part%2C%20with%20two%20conditions%2C%20and%20it%20is%20not%20working%20%3A(.%20If%20I%20only%20set%20one%20condition%2C%20then%20the%20results%20shows%20up%20fine%2C%20but%20two%20conditions%2C%20and%20nothing%20happens.%20This%20is%20my%20query%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CVIEW%3E%3CBR%20%2F%3E%3CQUERY%3E%3CBR%20%2F%3E%3CORDERBY%3E%3CBR%20%2F%3E%3CFIELDREF%20name%3D%22%26quot%3BTitle%26quot%3B%26lt%3BBR%22%3E%3C%2FFIELDREF%3EAscending%3D%22TRUE%22%26gt%3B%3C%2FORDERBY%3E%3CBR%20%2F%3E%3C%2FQUERY%3E%3CBR%20%2F%3E%3CWHERE%3E%3CBR%20%2F%3E%3CAND%3E%3CBR%20%2F%3E%3CBEGINSWITH%3E%3CFIELDREF%20name%3D%22%26quot%3BTitle%26quot%3B%22%3E%3C%2FFIELDREF%3E%3CVALUE%20type%3D%22%26quot%3BText%26quot%3B%22%3EI-0%3C%2FVALUE%3E%3C%2FBEGINSWITH%3E%3CBR%20%2F%3E%3CBEGINSWITH%3E%3CFIELDREF%20name%3D%22%26quot%3BTitle%26quot%3B%22%3E%3C%2FFIELDREF%3E%3CVALUE%20type%3D%22%26quot%3BText%26quot%3B%22%3EI-1%3C%2FVALUE%3E%3C%2FBEGINSWITH%3E%3CBR%20%2F%3E%3C%2FAND%3E%3CBR%20%2F%3E%3C%2FWHERE%3E%3CBR%20%2F%3E%3C%2FVIEW%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20anyone%20guide%20mee%20in%20where%20I%20am%20doing%20something%20wrong%3F%20I%20have%20tried%20with%20the%20Or%20condition%20as%20well%2C%20but%20that%20did%20not%20help%20%3A(.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20some%20of%20you%20hard%20coders%20can%20figure%20this%20out.%3C%2FP%3E%3CP%3ETHX%20in%20advance.%3C%2FP%3E%3CP%3E%2FFrank%20Nielsen%2C%20Denmark%3C%2FP%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1008486%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1010308%22%20slang%3D%22en-US%22%3ERe%3A%20CAML%20Query%20with%20two%20conditions%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1010308%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F187265%22%20target%3D%22_blank%22%3E%40Frank%20Nielsen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Frank%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENot%20sure%20which%20version%20of%20SharePoint%20you%20are%20usingQuery%20looks%20OK%20for%20me%20%2CAND%20condition%20wont%20work.%3C%2FP%3E%3CP%3EMake%20sure%20you%20use%20OR%20condition%2CHowever%20we%20can%20design%20the%20CAML%20Query%20using%20the%20UI%20Tools%20or%20google%26nbsp%3B%20with%20CAML%20Query%20Builder%20%2FCAML%20Designer%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ehere%20is%20the%20link%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.biwug.be%2Fresources%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.biwug.be%2Fresources%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20this%20works%20for%20Sharepoint%20online%20too%2Cjust%20check%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1010446%22%20slang%3D%22en-US%22%3ERe%3A%20CAML%20Query%20with%20two%20conditions%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1010446%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F453843%22%20target%3D%22_blank%22%3E%40O365Developer%3C%2FA%3E%26nbsp%3BTHX%20for%20quick%20reply.%20I%20am%20sorry%20I%20did%20not%20mention%20wich%20version%20of%20SharePoint%20I%20am%20using.%20It%20is%20SharePoint%20Online%2C%20and%20I%20was%20thinking%20that%20the%20highlitetd%20webpart%20in%20Sharepoint%20Online%20is%20not%20supporting%20two%20CAML%20conditions.%20I%20have%20seen%20a%20lot%20with%20SharePoint%20through%20the%20years%2C%20so%20I%20would%20not%20be%20surprised%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Fcryingwhilelaughing_anim.gif%22%20alt%3D%22%3Acryingwithlaughter%3A%22%20title%3D%22%3Acryingwithlaughter%3A%22%20%2F%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20will%20try%20your%20suggestion%20and%20use%20the%20Or%20function%20instead.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2FFrank%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1010455%22%20slang%3D%22en-US%22%3ERe%3A%20CAML%20Query%20with%20two%20conditions%20not%20working%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1010455%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F453843%22%20target%3D%22_blank%22%3E%40O365Developer%3C%2FA%3E%26nbsp%3BThe%20%22Or%22%20did%20the%20trick.%20Thanks%20a%20lot.%20I%20am%20happy%20happy%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Flaugh_40x40.gif%22%20alt%3D%22%3Alol%3A%22%20title%3D%22%3Alol%3A%22%20%2F%3E%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Flaugh_40x40.gif%22%20alt%3D%22%3Alol%3A%22%20title%3D%22%3Alol%3A%22%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Frank Nielsen
Occasional Contributor

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

3 Replies
Solution

@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.

@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

Hi @O365Developer The "Or" did the trick. Thanks a lot. I am happy happy :lol::lol:

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
48 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
30 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies