SharePoint 2010 REST filter from current user

Using REST in SharePoint 2010, how do you select / filter list lines that belong to a registered user (be it filtering by author, editor, or by Person field)

eg.

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, it seems Author, Editor and any other Person field are stored as Ints and renamed to CreatedById and ModifiedById. If you request a list, all you got is

 <d:CreatedById m:type="Edm.Int32">1</d:CreatedById> 

What if I want to return an NT username? Do I have to execute another request somewhere to get the Int value for a specific user?

+4
source share
2 answers

cm.

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'

+3
source

You can also use this with UserID. Extract UserId with code:

var userId = _spPageContextInfo.userId;

and use it in the url as below:

 "http://spdevportal/dev/Lab2/_vti_bin/ListData.svc/IPParams?$filter=CreatedById eq"+userId 

Example: http://spdevportal/dev/Lab2/_vti_bin/ListData.svc/IPParams?$filter=CreatedById eq 213

It will provide you with all the items created by the user of the current log.

You can also add an additional filter using 'and'

 "http://spdevportal/dev/Lab2/_vti_bin/ListData.svc/IPParams?$filter=CreatedById eq"+userId+" and StatusValue eq 'approved'" 

Example:

 "http://spdevportal/dev/Lab2/_vti_bin/ListData.svc/IPParams?$filter=CreatedById eq 213 and StatusValue eq 'approved'" 
+5
source

Source: https://habr.com/ru/post/1439566/


All Articles