0

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?

<Query>
    <Where>
        <And>
            <Eq>
                <FieldRef Name="Title" />
                <Value Type="Text">var1</Value>
            </Eq>
            <Eq>
                <FieldRef Name="Subchannel" />
                <Value Type="Text">var2</Value>
            </Eq>
        </And>
     </Where>
</Query>

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.

0

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 '14 at 7:58

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.