4

The list should be filtered like this SQL given below:

select * from SPLIST where status="complete" AND Assigned To="Samrat Sarkar"

I have this CAML query but it doesnt work:

"<View>
  <Query>
    <Where>
      <Eq>
        <FieldRef Name='Status'/><Value Type='Text'>" + "Open" + "</Value>
      </Eq>
       <And>
      <Eq>
        <FieldRef Name='Assigned To'/><Value Type='Text'>" + "Samrat Sarkar" 
         + "</Value>
      </Eq>
      </And>
    </Where>
  </Query>
 </View>";

Please help.

  • Change Assigned To to Assigned_x0020_To (which is the internal name) – Mike Sep 7 '17 at 16:36
  • 1
    The internal name is AssignedTo (assuming the OOTB Assigned To column) – theChrisKent Sep 7 '17 at 17:20
  • good catch @theChrisKent , I was assuming the space encoding. – Mike Sep 7 '17 at 17:21
4

Refer below query.

And one more thing as Mike commented, you will have to use internal name of you field (e.g. Assigned_x0020_To)

"<View>
   <Query>
      <Where>
         <And>
            <Eq>
               <FieldRef Name='Status' />
               <Value Type='Text'>Open</Value>
            </Eq>
            <Eq>
               <FieldRef Name='Assigned_x0020_To' />
               <Value Type='Text'>Samrat Sarkar</Value>
            </Eq>
         </And>
      </Where>
   </Query>
</View>";
3
<View>
  <Query>
    <Where>
      <And>
        <Eq>
          <FieldRef Name='Status'/><Value Type='Choice'>Open</Value>
        </Eq>
        <Eq>
          <FieldRef Name='AssignedTo'/><Value Type='UserMulti'>Samrat Sarkar</Value>
        </Eq>
      </And>
    </Where>
  </Query>
 </View>

The And needs to wrap the 2 conditions. Additionally, the internal name of the Assigned To column is AssignedTo and it is a multi person field (UserMulti) assuming this is a tasks list. The Status column is also of type Choice.

0

When using CAML queries I would advise to use a builder, just like Microsoft also advises here: https://msdn.microsoft.com/en-us/library/ff647340.aspx

There are also others out there if you search a bit.

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.