My recent task was to create a custom workflow activity that users could access in SharePoint Designer which would be used to retrieve a users manager from Active Directory. No, you don’t get this out of the box. But you almost do! And with this post it should be taken care of.

I won’t cover the basics for how to create a custom activity and deploy it for use with SPD. There are many other posts that cover those details. And speaking of being lazy, turns out there is a code sample in the ECM Starter Kit that is a great starting point for exactly what I was trying to accomplish (download it, install it, sample located in “ECM Starter KitCode SamplesWorkflowECMActivities”). Through a lot of trial and error (no debug capability in clients dev site) I was able to modify it to be a bit more stable. I added logic to handle things like AD properties not existing and manager name being in a couple different formats ({First Name} {Last Name} and {Last Name}, {First Name}).

I’ll post the code for the SetManagerFields method as that’s where all the customization takes place.

Pretty nice, right? I know, most of that I didn’t even write. I’ll shut up. But…Now when a user uses this activity in their workflow in SPD, they get a nice response back even if the manager property isn’t even there (which is possible depending on the quality of the directory.) After running the action, they can check the IsSuccess variable to determine if the manager was found. Then act accordingly.