CAML Query Help required

Hi,

I am Using SharePoint Online. I want to create a View on List based on User using CAML Query. Let say the list has following columns

Type,Data1, Data2, Country

T1,1, 1, US

T2,2, 2, CA

T3, 3, 3, US

I want if user 1 signs in, i need to display all the items where country is US and so. 

Need help.

T

August 20th, 2015 7:48am

Hi Fahad,

Please use the following tool to generate the CAML query based on the columns from the selected list.

CAML Designer for SharePoint 2013

Please don't forget to mark it as answered, if your problem resolved or helpful.

Free Windows Admin Tool Kit Click here and download it now
August 20th, 2015 10:36am

Cab you please explain how would i get the current user. My query would be like this:

Where

And

EQ

Current user = Fahad

EQ/

EQ

Client = US

EQ/

And/

Where/

I just need to know how whould i get to know if current user logged in is, let say, Fahad.

August 20th, 2015 2:08pm

Hi,

Please refer to the following blog post.

https://kamilmka.wordpress.com/2011/04/22/caml-query-to-retrieve-data-for-current-user/

Replace the Author field with your own fieldname.

   <Where>
      <And>
         <Eq>
            <FieldRef Name='Author' />
            <Value Type='Integer'>
               <UserID />
            </Value>
         </Eq>
         <Eq>
            <FieldRef Name='Client' />
            <Value Type='Choice'>US</Value>
         </Eq>
      </And>
   </Where>

Please don't forget to mark it as answered, if your problem resolved or helpful.


  • Edited by Mokhtar Bepari Thursday, August 20, 2015 3:54 PM add CAML code
Free Windows Admin Tool Kit Click here and download it now
August 20th, 2015 3:38pm

Hi,

Please refer to the following blog post.

https://kamilmka.wordpress.com/2011/04/22/caml-query-to-retrieve-data-for-current-user/

Replace the Author field with your own fieldname.

   <Where>
      <And>
         <Eq>
            <FieldRef Name='Author' />
            <Value Type='Integer'>
               <UserID />
            </Value>
         </Eq>
         <Eq>
            <FieldRef Name='Client' />
            <Value Type='Choice'>US</Value>
         </Eq>
      </And>
   </Where>

Please don't forget to mark it as answered, if your problem resolved or helpful.


  • Edited by Mokhtar Bepari Thursday, August 20, 2015 3:54 PM add CAML code
August 20th, 2015 3:38pm

What would be the field name of Current User?
Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 8:09am

Hi,

<UserID/> will be current user, no need to give any thing.  If you want to check created by field use "Author" and if you want to check modified by field use "Editor".

https://kamilmka.wordpress.com/2011/04/22/caml-query-to-retrieve-data-for-current-user/

   <Where>
      <And>
         <Eq>
            <FieldRef Name='Author' />
            <Value Type='Integer'>
               <UserID />
            </Value>
         </Eq>
         <Eq>
            <FieldRef Name='Client' />
            <Value Type='Choice'>US</Value>
         </Eq>
      </And>
   </Where>

Please don't forget to mark it as answered, if your problem resolved or helpful.

August 21st, 2015 10:44am

Hi,

<UserID/> will be current user, no need to give any thing.  If you want to check created by field use "Author" and if you want to check modified by field use "Editor".

https://kamilmka.wordpress.com/2011/04/22/caml-query-to-retrieve-data-for-current-user/

   <Where>
      <And>
         <Eq>
            <FieldRef Name='Author' />
            <Value Type='Integer'>
               <UserID />
            </Value>
         </Eq>
         <Eq>
            <FieldRef Name='Client' />
            <Value Type='Choice'>US</Value>
         </Eq>
      </And>
   </Where>

Please don't forget to mark it as answered, if your problem resolved or helpful.

Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 10:44am

How would i write a query below in CAML

If (CurrentUser=="Fahad Ahmed")

September 11th, 2015 12:35am

Hi,

You cannot pass the string like that...But you can pass the user id and get the details...

<FieldRef Name='Author' LookupId='TRUE' />
<Value Type='Integer'>" + _id + @"</Value>
Please don't forget to mark it as answered, if your problem resolved or helpful.

Free Windows Admin Tool Kit Click here and download it now
September 12th, 2015 12:24am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics