1

I got a question regarding CAML and retrieving data. I need to determine the proper people based upon the places user submits.

So I created the lists People-Place where I have column Place and column User.

Now I would like to retrieve people from SP List based on the user Places choice. I was able to do it for each item separately - place A -> person A. This is easy with Eq operator in CAML.

Now I want to go a little bit further- user uses many places (place A, place B, place C). I pass the values into my retrieving function. I don't want to split my input string and iterate over asynchronous function. Is there any way how to check if the field with name People is a substring of Query value? In JS the indexOf function could do the job. Is sth similar in CAML or do I really need to use a loop?

Thanks in advance for you help !

1

Absolutely Yes, you can do this in CAML query also. You have to use tag name while querying. See example

<Where><And><Eq><FieldRef Name='UserName' /><Value Type='User'>User_A</Value></Eq><Contains><FieldRef Name='Place' /><Value Type='Text'>Place_A</Value></Contains></And></Where>

Assume you have places like Place_A, Place_AA, Place_AAA, Place_B, Place_C, A_Place_A, ...etc. Now when you query this using above code, it will include all the places where "Place_A" is the sub-string of places name.

Enjoy!

  • Thanks for answer! I am not really sure if I got this properly. Maybe I explained my problem wrong. The person is a field I want to retrieve e.g Person A- Place A Person B- Place B Person A- Place C Person C - Place D The input values is let's say in form: (Place C; Place D)as a string. Based upon this string I want to find my guys from SP List. For this example it would be Person A and Person C. I could do it by splitting string putting it into array and calling function i-times but I wonder if there is a CAML possibility (but without User like above)? – EmJotPe Jul 24 '17 at 12:55
  • See, simply you can put any number of AND , OR conditions to your query. That is the way only. eg. place C, and place D you have split and incude them in query, one by one – DvG Jul 24 '17 at 17:43
  • This is exactly what I was afraid of. Anyway thank you very much for your help :) – EmJotPe Jul 25 '17 at 10:15
0

You can use Contains filter in CAML query to get results.

<View>
 <Query>
<Where>
<Or>
<Contains>
    <FieldRef Name='Field1' />
    <Value Type='Text'>test4</Value>
  </Contains>
<Or>
<Contains>
    <FieldRef Name='Field1' />
    <Value Type='Text'>test3</Value>
  </Contains>
<Or>
  <Contains>
    <FieldRef Name='Field1' />
    <Value Type='Text'>test1</Value>
  </Contains>
  <Contains>
    <FieldRef Name='Field1' />
    <Value Type='Text'>test2</Value>
  </Contains>
</Or>
</Or>
</Or>
</Where>

You can build dynamic query based on your fields. Hope this helps you :)

  • This is the same answer as first answer provided – DvG Jul 25 '17 at 10:23

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.