views:

58

answers:

1

Hello All,

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?

A: 

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
@Kit Menke....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
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
@Kit Menke..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
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