{"id":1147,"date":"2007-01-29T15:06:00","date_gmt":"2007-01-29T20:06:00","guid":{"rendered":"http:\/\/blogs.devhorizon.com\/reza\/?p=1147"},"modified":"2007-01-29T15:06:00","modified_gmt":"2007-01-29T20:06:00","slug":"view-of-a-list-to-filter-list-items-for-the-current-logged-in-user","status":"publish","type":"post","link":"https:\/\/blogs.devhorizon.com\/reza\/2007\/01\/29\/view-of-a-list-to-filter-list-items-for-the-current-logged-in-user\/","title":{"rendered":"View of a List to filter list items for the current logged in user"},"content":{"rendered":"<p><P>This has become a serious requirement in two of the projects we are dealing with, so I thought it is worth sharing with the community.<\/P><br \/>\n<P>Let&#8217;s say, you have a list for which you want to display all the list items Created By the currently logged in user. There are two ways to do it:<\/P><br \/>\n<P>A) Through web browser interface: List settings &#8211;&gt; Filter &#8211;&gt; Choose Created By field and make it equal to [Me]<\/P><br \/>\n<P>B) If you want to put it in your site def, things are done a little bit differently. <\/P><br \/>\n<P>First of all, the [Me] operator only works on lookup fields bound to the list &#8220;user information&#8221; and on the built-in system fields (i.e. &#8220;created by&#8221; OR &#8220;modified by&#8221;)<\/P><br \/>\n<P>Secondly, at the end of the day [Me] is translated to an integer. In order to implement such a functionality you should locate the Schema.xml of the list or document library for which you wish to create this view for and follow these steps:<\/P><br \/>\n<P>1) Open Schema.xml<\/P><br \/>\n<P>2) Find views element <\/P><br \/>\n<P>3) Either create a new view element or insert the following snippet into one of the existing views for which you want to implement the filter:<\/P><br \/>\n<P>&nbsp; &lt;Query&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Where&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Eq&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;FieldRef Name=&#8221;Author&#8221; \/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Value Type=&#8221;Integer&#8221;&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;UserID Type=&#8221;Integer&#8221; \/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/Value&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/Eq&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/Where&gt;<BR>&nbsp;&nbsp; &lt;\/Query&gt;<\/P><br \/>\n<P><QUERY><BR>&nbsp;&nbsp;This will turn out to an actual T-SQL with where clause and equal operator (<EQ> is translated to &#8220;=&#8221;) at runtime. <\/P><br \/>\n<P>4) Save Schema.xml <\/P><br \/>\n<P>5) Restart IIS<\/P><br \/>\n<P><BR>Now you have the view with a filter on the current logged in user. In next post I will show you how to implement the same functionality using content query web part (CQWP) which is awesome for cases of this kind.<BR><\/P><\/p>\n<hr align=left noshade size=10 width=50%>\n","protected":false},"excerpt":{"rendered":"<p>This has become a serious requirement in two of the projects we are dealing with, so I thought it is worth sharing with the community. Let&#8217;s say, you have a list for which you want to display all the list items Created By the currently logged in user. There are two ways to do it: [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1147","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/1147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/comments?post=1147"}],"version-history":[{"count":0,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/1147\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/media?parent=1147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/categories?post=1147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/tags?post=1147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}