Reputation: 2474
Using REST in SharePoint 2010, how do you select / filter rows of a list which belong to the user currently logged in (whether it's a case of filtering by Author, Editor, or by a Person field)
e.g.
http://myserver/_vti_bin/ListData.svc/Test?$filter=Author eq Me
I know in SP2007, using caml you can use the UserID element which represents the value of the current user.
EDIT: Humm, seems the Author, Editor and any other Person field are stored as Ints and are renamed to CreatedById and ModifiedById. If you query a list all you get back is
<d:CreatedById m:type="Edm.Int32">1</d:CreatedById>
What if I want to get back the NT name of the user? Do I have to do another query somewhere to get the Int value for a certain user?
Upvotes: 4
Views: 6403
Reputation: 113
You can also use this with UserID. Retrieve UserId by using code:
var userId = _spPageContextInfo.userId;
and use it in URL as below:
"http://spdevportal/dev/Lab2/_vti_bin/ListData.svc/IPParams?$filter=CreatedById eq"+userId
Ex: http://spdevportal/dev/Lab2/_vti_bin/ListData.svc/IPParams?$filter=CreatedById eq 213
It will give you all the items created by Currently LoggedIn user.
You can also add some additional filter using 'and'
"http://spdevportal/dev/Lab2/_vti_bin/ListData.svc/IPParams?$filter=CreatedById eq"+userId+" and StatusValue eq 'approved'"
Ex:
"http://spdevportal/dev/Lab2/_vti_bin/ListData.svc/IPParams?$filter=CreatedById eq 213 and StatusValue eq 'approved'"
Upvotes: 5
Reputation: 46
see
http://spdevportal/dev/Lab2/_vti_bin/ListData.svc/IPParams?$expand=CreatedBy
and use
http://spdevportal/dev/Lab2/_vti_bin/ListData.svc/IPParams?$filter=CreatedBy/Account eq 'OFFICE\alexandr.pletnev'
Upvotes: 3