Mittwoch, 3. Oktober 2012

Allow only certain people in a people picker

How to allow only certain users to be chosen from the people picker


Some time passed without any posts as I had to get my job done ;-)

And while working on a small project I saw a ... let's say not so optimal list form.

There was a field where the user had to enter the email address of a responsible manager. But only certain managers were to be selected here. So what they made was just creating a radio button list with all managers which were also placed in a certain group.

Their amount was around 30. So you can imagine how the form looked like. Of course they have could just use a dropdown list. Still it wouldn't be very good-looking and easy to use.

Furthermore it was desired that the administrators of the SharePoint site only need to add managers to the group. The field selection should be populated automatically based on the list. This could have been done by coding, but I didn't like that idea.

So I came up with my own one which was just using integrated SharePoint features.

So what do we need?

Actually only two things:
  1. a user group which includes all the people that should be selectable.
  2. a field in the list where the person is actually going to be selected

Let's get it done

  • For the field where the person is to be selected, set its type to "People Picker".
  • When creating/editing the people picker field in the list settings you have the option to change some of its properties.
  • One of them is where the pickable people come from. In many enterprise environments the Active Directory users will be the default.
  • But instead you want the group with the people to be selectable, so you replace all active sources by your desired group.
  • That's it. You can save your changes.

What's happening now, when users try to enter a wrong person which is not in the group, they can't save the item (unless you set the field to be optional).
Furthermore you can use functionalities like entering email addresses or names and the automatic user check finds the person which fits the inputs.

Another huge advantage is that you simply need to add a user to the group and he will automatically appear in the people picker. So you don't have to worry about editing a field as well.

I hope this could help you, if not or if you just want to say "thank you", please leave a comment.

Donnerstag, 3. Mai 2012

How to use folders in SPD workflows

Usage Guidelines when using folders in SPD workflows

When using automated folders in SharePoint lists you have to pay attention. To what exactly, is shown below.

  • The name of folders are set in the field "Title". That also means these values have to be unique.
  • That also means, for folder lookups, general items should not use the "Title" field. Consider creating a new field for those items' names. Items having folders' titles can lead to false lookups (and combined lookups are not possible in SPD workflows)
  • Before creating folders in a workflow, you should always make sure that the folder does not already exist.
  • Before moving items into a folder, you should make sure that the folder exists.
  • When you have folders, you should also use folder level security (when you need some kind of permission management)

This should wrap things up for using folders in SharePoint lists. If you have any questions or suggestions, please leave a comment.

Check if a Sharepoint list folder already exists

How-To: Check if a folder already exists using a SPD workflow

Sometimes you might want to check if a folder already exists in a certain list before doing some actions.

This check is not very obvious, but still pretty easy.

  1. Create a string workflow variable.
  2. Now create a lookup for your folder and set the variable to the folder's title. Take a look here for some helpful information and usage guidelines when it comes to list folders.
  3. The actions dependent of the existence of the folder have to be placed inside an if-statement
  4. E.g. the if-statement should be like "if [variable] not equals [folder name]" if you want the actions only to be run when the folder does not exist

For example, you could only create folders if they do not exist already.

Set Sharepoint list folder permissions

How-To: Set folder permissions using a SPD workflow

This tutorial is going to be rather short since the procedure is the same as setting item permissions.

As you may know using item level permission security is not very performant, especially when having many items in one list. To raise the performance, folder level security is recommended.

Basically all this is about is placing items which shall have the same permissions into one folder having exactly these permissions set to it. The items inside the folder are automatically inheriting the folder permissions and the list is sped up. :-)


To set folder permissions in a SPD workflow, you just have to follow these steps:

  1. Inside a SPD workflow, choose the "Replace Item Permission" activity. If the activity is not present you might have to use an impersonation step.
  2. Create a lookup which returns the folder (Best practice here: Set the permissions after creating the folder which returns the ID of the folder)
  3. Set up your desired permissions.

Now the folder gets his permissions assigned automatically. All items inside the folder will inherit these permissions.

Please note: Always consider using groups for permissions. Assigning users directly is definitely not a good practice.

Move items into a SharePoint list folder

How-To: Move items into a folder using a SPD workflow

In one tutorial I explained how to create folders using a SPD workflow. Only having folders when you still need to create all items in the according folder manually doesn't make too much sense.

So I figured out how to move items into folders using SPD workflows.


What do you need?

All you need to do before moving items is to assign the folder content type to the according lists. How this can be done is explained here.


Let's get it done

Actually there is no standard workflow activity moving items. So we are going to use the "Create List Item" activity. You might think "Copy List Item should also work.". Well, actually, it does not work for this purpose since you cannot change any fields of the item to be moved.

So here is how you move items:

  1. Add the "Create List Item" activity.
  2. Of the new item, set all field values to the ones of the current item.
  3. Additionally, set the field "Folder" to the name of the folder where the new item should be placed in. (This is where "Copy List Item" would fail.)
  4. Afterwards delete the current item, so only the new one stays present.
Please note: The folder for the new item must already exist.
Of course you can also create completely new items inside a folder. :-)

Create folders using a SPD workflow

How-To: Create folders in a SharePoint list using a SPD workflow


As you may know SharePoint lists are only supporting a limited number of items. For example, only 5000 items can be retrieved in a view. To get your list structured the usage of folders is recommended.

In the future I might provide a tutorial for activating the option to manually create folders in a list, though this is actually pretty simple. I will post a link here if I do so.

But you may ask "What if I don't want to create the folders manually?".Well, you could, of course, write your own application or event receiver creating all the folders for you. Still some of you might feel uncomfortable programming stuff for SharePoint or in general.

Well, there is yet another solution for our folder problem in SharePoint, at least in SP 2010.
All you need is the SharePoint Designer 2010 which can be downloaded from Microsoft directly. It enables you to create custom workflows which go far beyond what SharePoint provides out of the box.

After installing and setting up SPD, you can move on creating your automated folder creation workflow using my tutorial.


Now let's get it done

 

Prepare the list

For a custom workflow being able to create folders, you need to assign the folder content type to the list. To do so, you have two options: using the SharePoint Designer or your browser.

I will explain the more easier one (in my opinion), using the browser.

  1. Open the list in an internet browser. There will be an option bar at the top.
  2. Select "List" and choose "List Settings" in the new ribbon.
  3. Now, if you haven't done so already, click on "Advanced Settings", activate the option "Enable management of content types" and click on "OK".
  4. Head back to the list settings.
  5. Now there is a new section listing all content types for the list. Click on "Add from existing content types".
  6. In the new page, select "Folder Content Tpes" from the dropdown menu.
  7. Add the content type named "Folder" to the list content types by selecting it and clicking on the arrow pointing to the right.
  8. Click on "OK" to save the new assignment.
Please note: Still the folder won't appear in the content type section of the list settings, which I'm not sure of whether it is a bug or not. That also means that you cannot remove the folder content type from the list.


Create your workflow

As your workflow probably will have a different purpose than the one I made, I will only explain the important part. :-)

A folder is generally just a list item. So we are going to build on that.

  1. To create a folder, choose the action "Create a list item".
  2. Click on the blue part to open a window asking for some information.
  3. Choose the list where the folder shall be added from the dropdown field.
  4. If your list has multiple content types, a field to assign a value to, will automatically be added. It is called "Content Type ID". If it is not present, click on "Add" to add this field.
  5. For the value of this field you will have a dropdown selection from which you have to choose "Folder".
  6. To give the folder a name, also add the field "Title" and give it a value of you choice.
Please note that this value for "Title" has to be unique, so you might have to change your lookup or logic accordingly. That means that you should implement a check if a folder already exists, explained here.

Final notes

Of course just having the folder might not be enough. So check out my tutorials on how to place a list item inside a folder and how to set permissions for a folder, both using SharePoint Designer Workflows.

Hello World!

Hello World!

First of all, before beginning sharing some helpful SharePoint tips, I want to introduce myself.

My name is Kevin, I'm 22 years old and currently studiying Applied Informatics. As I'm going to graduate this year, I already had the chance to gain some experience in various fields of programming, including SharePoint. I worked with SP 2007 and 2010 as well.

Even though I'm not Microsoft certified, I managed to solve some SharePoint problems which in my opinion are pretty common and should have been handled by Microsoft directly. Instead I had to waste a plenty of time trying to find a suitable workaround.

Mostly the problem was that the solutions I found using Google were involving steps which were not available in my environment. For example in some cases I could not deploy custom code or change SharePoint settings which I had no access to.

To make your work easier and save you some time, I will post solutions for (in my opinion) probable problems here. Most of them are using out-of-the-box features or the SharePoint Designer.

The first one is the automated creation of folders in a SharePoint list, so check out this tutorial.

If you have questions regarding workflows, custom code or SharePoint in general, please don't hesitate to contact me.