I am going to implement a search query. I have 2 inputs user can give value or leave as empty. If user leave both input as empty and Search,,all items must populated. here I have static SP CAML query string. With 2 variables. but any variable can empty. When that variable empty I want to ignore that where part and get values. How can I do it?

                <FieldRef Name="Title" />
                <Value Type="Text">var1</Value>
                <FieldRef Name="Subchannel" />
                <Value Type="Text">var2</Value>

When var1 is empty I want to ignore that where condition. If both var1 and var2 is empty I want to get all items from list.

1 Answer 1


in Javascript

var query="Your Query here";if(var1=="" && var2!=""){query="First Query";}if(var1=="" && var2==""){query="Second Query";}if(var1!="" && var2!=""){query="Third Query";}

for returning all results you can use * as query term

  • I want to use one static query string. and '*' is not working in CAMl query builder.
    – devan
    May 2, 2014 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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