I decided to start a new blogging category named “Did You Know!?”. The idea behind this is that I write tips and tricks you might not think of or may not have heard but will help you and make you life easier.
Content Query WebPart – Audience targeting
Custom views for document library or lists webparts
So here we go:
Content Query WebPart – Audience targeting:
If you did not know you can filter content of the CQWP(and also in the code if you are using CrossListQueryInfo and CrossListQueryCache) by enabling Audience Targeting to the webpart.
What do you need to do to make it to work:
– Enable the CQWP Audience targeting – from the webpart properties
– Enable your content source to support audience targeting – Example: your library or list – from the list/library settings
Go to your library settings => Under “General Settings” => Select “Audience Targeting Settings” => Then enable Audience targeting by checking the checkbox.
After this you will get a new field to your list named as “Target Audiences”. Now when you create or edit items you will be able to chose an audience to that item. When a CQWP has audience targeting enabled what will happen is that the webpart will check the item audience targeting values and compare them to the user profile audiences. If the user is part of the items audience then the item will show up in the CQWP
– Configure your user profile service to support audience targeting
This is the tricky part. You need to configure a whole lot of places to get your audience targeting for a user to work so that webpart and other content related queries etc filter data properly.
I will do it in three parts the configuration:
1. Configure a Term Set in your Manage Metadata Service. Let’s say named “Location” that has 10 different countries your organization is interested in. This I will not explain in much detail. I hope you are familiar with MMS.
2. Go to your user profile service and create a new User Property(The picture below as an example). Also take notice(I do not remember exactly) but the privacy settings needs to set to everyone for this field to work properly.
3. Next assign to a user profile(s) a desired location to the newly created field.
4. Then lets create a new audience. In your user profile service go to “Manage Audiences”. Then Press the “New Audience” button. In the next view give the audience a name and an owner. And remember to select the rule strategy. I chose “Satisfy any of the rules so that I may include many rules to a single audience. This way I can aggregate two or more location to an audience and have any of them apply to an item and user.
5. In the next step select as an “Operand” property and select the location property we created and as the operator I would chose “Contains”. Next in the Value field select a value.
6. Now all you have to do is compile the audience. Press “Compile Audience”. After the compilation is complete you should see how many members are apart of this audience. Next when you assign this audience to an item any user from is apart of this audience through his location value that corresponds to the audience location values are going to see the CQWP item.
Custom views for document library or lists webparts:
You are able to create custom Views for your library or list webparts that show you content from your library. You are not limited to what you get once you add a documents library to a page as a webpart. BUT there is a catch!!! If you do select and existing view and use it to display content in a certain manner in a page YOU WILL NOT have a reference to that view in you library BUT A COPY held in the webpart. So lets say that you have a view that lists the TOP 5 newest documents in your library. You decided to add the document library webpart to a page, you then select this TOP 5 view, what happens is that you will get a copy that is not related to the original view of that document library. SO if you make changes to the view in the document library view those changes will not be seen in your webpart because it is not a reference. So remember this when you use a view from a library or list into your webpart.