0

I am making use of CAML Query to filter the records from list into DataTable. I have a SPUser Field in my list.

I am endeavoring to obtain the user id of each user in CAML Query. Any insights on how to achieve this?

Raghu
  • 185
  • 2
  • 7
  • 18

1 Answers1

2

Get items for an SPUser.ID:

<Where><Eq><FieldRef Name='Person' LookupId='TRUE'/><Value Type='Integer'>45</Value></Eq></Where>

Get items for the current user:

<Where><Eq><FieldRef Name='Person' LookupId='TRUE'/><Value Type='Integer'><UserID/></Value></Eq></Where>

Get items for a user's display name (what is displayed normally in the list):

<Where><Eq><FieldRef Name='Person'/><Value Type='Text'>Lastname, Raghu</Value></Eq></Where>

Kit Menke
  • 7,046
  • 1
  • 32
  • 54
  • ...Thank you very much for your reply..But my requirement is that I need to get a separate field using CAML Query which holds the IDs of all the users present in the list. Hope you get my point – Raghu Aug 06 '10 at 11:26
  • I'm not sure if I understand... a CAML query controls which rows are returned (not which fields). If you want to control which fields are returned, use the SPQuery.ViewFields property: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewfields.aspx – Kit Menke Aug 06 '10 at 15:38
  • .yes you are right...I know about the SPQuery.ViewFields property...however I need to obtain a field (User ID) from the list which doesn't exist in the list – Raghu Aug 07 '10 at 06:47
  • Oh I think I understand.. take a look here: http://stackoverflow.com/questions/1835355/get-username-from-sharepoint-user-field-in-list. Once you have the SPUser object you'll be able to get ID as well. – Kit Menke Aug 07 '10 at 13:45