Monday, April 5, 2010

Custom workflow step to add user to a security group

I’m not a developer per say…

It might not be the best way to start a post that is introducing a custom workflow step created by me, step that adds users to a SharePoint security group. But I have to be very honest and confess that the last time I opened up a visual studio and compiled anything was in 2006 for SP 2003.

OK, so here are the requirements I had. This is for a site that is built to facilitate a clinical trials and to be managed by study coordinators. The need for a custom activity step was caused by the need to have multiple study sites that would require the same functionality. A medical study coordinators that are not part of admin group, only contributors for a list in the study site, coordinators need to fill out new user information when a person agrees to participate in a study. Coordinators would fill our the person desired user id and their existing email, submit it and have a workflow to notify the external user to register on the site with the user name that was provided by the study coordinator.

As the next step the study participant would register on the site and once coordinators confirm that the new user registered on the site (FBA) they would go to the New User information list, check “User Registered” field and save this information. Update of this user record triggers a workflow that automatically adds this new user to the correct security group that would allow new users submit different online questioners and forms in a secured fashion once they log into the study site

OK, so that’s it with the overview of the process requirements. Lets look at the workflow step developed here to facilitate the process of adding new users to the right security group. Keep in mind this is running with elevated privileges, but the source code is available for you to modify it as desired. It’s available on the codeplex at http://natalyavoskresenskay.codeplex.com/ for download.

Steps to deploy the custom action:

1. download the DLL and register the DLL in the GAC.

2. Add to your web.config the following line in AuthorizeTypes section

<authorizedType Assembly="AddUserToGroup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e82442daf6f5df8e" Namespace="CustomAction" TypeName="*" Authorized="True" />

3. Create AddUserToGroup.ACTIONS file with text bellow and save it to the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\1033\Workflow folder. this file is also available for download.

<?xml version="1.0" encoding="utf-8"?>
<WorkflowInfo Language="en-us">
<Actions Sequential="then" Parallel="and">
  <Action Name="Add User to the group" ClassName="CustomAction.AddUserToGroup" Assembly="AddUserToGroup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e82442daf6f5df8e" AppliesTo="all" Category="ARC Action">
   <RuleDesigner Sentence="Add %1 to the %2 at site %3">
    <FieldBind Field="UserName" Text="Please put the User Name" Id="1" DesignerType="TextArea"/>
    <FieldBind Field="GroupName" Text="Please put the Group Name" Id="2" DesignerType="TextArea"/>
    <FieldBind Field="SiteName" Text="Please put the Site Name" Id="3" DesignerType="TextArea"/>
   </RuleDesigner>
   <Parameters>
    <Parameter Name="__Context" Type="Microsoft.Sharepoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" Direction="In"/>
    <Parameter Name="UserName" Type="System.String, mscorlib" Direction="In" />
    <Parameter Name="GroupName" Type="System.String, mscorlib" Direction="In" />
<Parameter Name="SiteName" Type="System.String, mscorlib" Direction="In" />
   </Parameters>
  </Action>
</Actions>
</WorkflowInfo>

Now open up a site and create a workflow in SharePoint Designer, “Add User to a group” step should be available in the list of action.

clip_image002

Add this step and fill in the info, User name, Group Name and the site URL, all fields are mandatory for the workflow action to run.

See example:

clip_image004

Enjoy :-)

1 comment:

Darsan clincia said...

Thank you so much for sharing nice information. Good stuff..Awesome...