Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Let's say I have a following taxonomy tree:

World
|--Germany
|    |-Frankfurt
|    |-Berlin
|--France
     |-Paris
     |-Lyon

My library documents are attributed with a column Location which uses this taxonomy tree.
It's simple to create a list view filter to show documents attributed only with Berlin or Lyon.
How is it possible to create a filter which would show only documents related to Germany (by which I mean Berlin or Frankurt etc.), or other taxonomy non-leaf node?

share|improve this question

2 Answers 2

up vote 2 down vote accepted
+50

You could programmatically create n views that would filter the list for the specific terms with the term has the view name.

If the number of locations is not so huge and rarely updated, I would create a small PowerShell script that would do the job proactively, otherwise, I would suggest creating a timer job that check for missing view based on available location terms and create them on the fly (you'll have the benefit in that way that it will work in all environments regardless of the term guid).

Something like this (not checking if the list view exist, neither retrieving the site the timer job but you get the idea :

SPSite site = new SPSite("your-site-collection-url");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Documents"];
SPViewCollection allviews = list.Views;
string viewName = "Germany";
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
viewFields.Add("Title");
string query = String.Format("<Where><Eq><FieldRef Name="LocationTaxonomyField' LookupId='TRUE' /><Value Type='Lookup'>{0}</Value></Eq></Where>", "{germany-term-id}");     
allviews.Add(viewName, viewFields, query, 100, true, false);
share|improve this answer

It is possible to accomplish with OOTB Metadata Navigation and Filtering Feature using Navigation hierarchies control.

Navigation hierarchies control allows to select an item in a hierarchy for a managed metadata column with filter for

  • single Term

  • Term with descendant child terms

enter image description here enter image description here


Applying filter in Navigation hierarchies control corresponds to initializing filters for XslListViewWebPart which in turn generates query (CAML Where element to be more precise ) for current View (actually the same way as filtering works in SharePoint Designer).

In our cases, the following queries will be generated:

CAML Where clause for filter Term with descendant child terms

   <Where>
    <In>
        <FieldRef Name="LocationTaxFieldName" LookupId="TRUE" />
        <Values>
            <Value Type="Integer">WssIdsOfGermanyTerm</Value>
            <Value Type="Integer">WssIdsOfBerlinTerm</Value>
            <Value Type="Integer">WssIdsOfFrankfurtTerm</Value>
        </Values>
    </In>
   </Where>

CAML Where clause for filter single Term

<Where>
        <In>
            <FieldRef Name="LocationTaxFieldName" LookupId="TRUE" />
            <Values>
                <Value Type="Integer">WssIdsOfGermanyTerm</Value>
            </Values>
        </In>
    </Where>

For more information about querying on Managed Metadata Field Values in SharePoint Server 2010 see MSDN

So, it is possible to create view (declaratively or programmatically) with such a filters.

share|improve this answer
    
I'm aware of this feature, however the question is, is there any way to remember such choice and associate it with a view? I mean any way, GUI or CAML. –  soliloquyy Dec 31 '12 at 11:51
    
soliloquyy, answer has been updated with information about generated CAML for filters. –  Vadim Gremyachev Jan 2 '13 at 14:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.