Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have one Date and time column and text colum. I need to retrieve list item value based on this both column using CAML query..

For ex:

Columname---> Date value for date would be-6/1/2013 and another date would be 6/3/2013

Columnname-> Team Value for Team would be -A

I could not able to install U2u Builder in my machince. My CAML query as mentioned below

<Where><And><Eq><FieldRef Name='Team' /><Value Type='Text'>PP</Value></Eq><Gt><FieldRef Name='Date' /><Value IncludeTimeValue='False' Type='DateTime'>6/1/2013</Value></Gt><Lt><FieldRef Name='Date' /><Value IncludeTimeValue='False' Type='DateTime'>6/2/2013</Value></Lt></Eq></And></Where>

Please can any one give Correct CAML query for this condition. i am going to get the values in javascript.

#
<script type="text/javascript">ExecuteOrDelayUntilScriptLoaded(MainFunction, "sp.js");
        function MainFunction() {
            var myQueryString = "<Where><And><Eq><FieldRef Name='Team' /><Value Type='Text'>PP</Value></Eq><Gt><FieldRef Name='Date' /><Value IncludeTimeValue='False' Type='DateTime'>6/1/2013</Value></Gt><Lt><FieldRef Name='Date' /><Value IncludeTimeValue='False' Type='DateTime'>6/2/2013</Value></Lt></Eq></And></Where>";
            var myContext = new SP.ClientContext.get_current(); ;
            var myWeb = myContext.get_web();
            var myList = myWeb.get_lists().getByTitle("as");
            var myQuery = new SP.CamlQuery();
            myQuery.set_viewXml(myQueryString);
            myItems = myList.getItems(myQuery);
            myContext.load(myItems, 'Include(ID,Title,Tower)');
            myContext.executeQueryAsync(Function.createDelegate(this, GetListDataSuccess), Function.createDelegate(
this, GetListDataFail));
            //alert('Query started, but not yet finished!'); 
        }
        function GetListDataFail(sender, args) {
            // Show error message
            alert('GetListDataFail() failed:' + args.get_message());
        }
        function GetListDataSuccess(sender, args) {
            var currListItemCount = myItems.get_count();
            //alert(currListItemCount + ' Items found!'); 
            var currItemEnumerator = myItems.getEnumerator();
            var currItemDetails = '';
            // Loop through all items 
            while (currItemEnumerator.moveNext()) {
                // Get current item 
                var currItem = currItemEnumerator.get_current();
                // Concatenate values 
                if (currItemDetails == "")
                    currItemDetails = currItem.get_item("Tower");
                else
                    currItemDetails = currItemDetails + ';' + currItem.get_item("Tower");
            }
            // Show details 
            //alert(currItemDetails); 
            callCombo(currItemDetails);
        }
        function addValuetoCombo(txtvalue, ddl) {
            var option = document.createElement("option");
            option.text = txtvalue;
            option.value = txtvalue;
            try {
                ddl.add(option, null); //Standard 
            } catch (error) {
                alert('error');
                ddl.add(option); // IE only
            }
        }
        function callCombo(msg) {
            var str_array = msg.split(';');
            var combo = document.getElementById("ddlbox");
            //alert(msg);
            for (var i = 0; i < str_array.length; i++) {
                // Trim the excess whitespace.
                //alert(str_array[i]);
                var objText = str_array[i];
                // Add data to dropdown
                addValuetoCombo(objText, combo);
                //alert(i);
            }
        }
</script>
share|improve this question
add comment

1 Answer

First of all - you have aמ unnecessary closing tag </Eq> at the end.

Also, you can not put more than 2 conditions in the AND or OR,

In addition, You have to convert your DateTime object to a ISO8601 format.

So your CAML should look like this:

<Where>
  <And>
    <Eq>
      <FieldRef Name='Team' />
      <Value Type='Text'>PP</Value>
    </Eq>
    <And>
      <Gt>
        <FieldRef Name='Date' />
        <Value IncludeTimeValue='False' Type='DateTime'>SPUtility.CreateISO8601DateTimeFromSystemDateTime(FromDate)</Value>
      </Gt>
      <Lt>
        <FieldRef Name='Date' />
        <Value IncludeTimeValue='False' Type='DateTime'>SPUtility.CreateISO8601DateTimeFromSystemDateTime(ToDate)</Value>
      </Lt>
    </And>
  </And>
</Where>
share|improve this answer
    
I have try with your above code, it displaying all list item values from the list. –  madhan Jul 2 '13 at 10:29
    
I would recommend you to run any of the conditions separately and see which one is the problem. –  banana Jul 2 '13 at 10:48
    
Hi For Date field it is reterving all items from the list... –  madhan Jul 2 '13 at 11:17
    
Even when you run only one of them without the other conditions? –  banana Jul 2 '13 at 11:46
    
Yes..It is reterving all items from the list... –  madhan Jul 2 '13 at 12:22
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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