Custom activities for your workflows

17 05 2007

When working with workflows, you will quite soon hit the dead end of the available possibilities and go “Hmmm, how can I make this a little different?”. That’s our spirit. One of the approaches is to create custom activities that you can add to your workflows. This sample creates a custom activity that will appear Custom activities should be developped and installed as features for simplicity of deployment and for keeping your house clean.

So, what do we need?

  1. Get a sample code from here.
  2. Craft it your way and BTW, to debug workflows, attach your debugger to the process w3p.exe that refers workflows.
  3. Sign your dll (need help on this? See How to install an assembly into the Global Assembly Cache in Visual C#)
  4. Deploy your dll to the GAC(ok, ok you didn’t create the feature yet… just copy/paste it or drag & drop your dll to your GAC folder it should be something like c:\windows\assembly)
  5. Edit the web.config of the site where you want this activated
    1. look for the section <authorizedTypes></authorizedTypes>
    2. add the node 

  6. <authorizedType Assembly="<NAME.OF.YOUR.CLASS>, Version=, Culture=neutral, PublicKeyToken=<PUBLIC_KEY_HERE>" Namespace="<NAME.OF.YOUR.CLASS>" TypeName="*" Authorized="True" />

  7. Edit your WSS.ACTIONS file (look in  C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\Workflow\)
  8. Look for the section <ACTIONS></ACTIONS>
  9. Add a node

<Action Name="<DISPLAY NAME YOU WANT>" ClassName="<CLASS_NAME>" Assembly="<CLASS_NAME>, Version=, Culture=neutral, PublicKeyToken=<PUBLIC_KEY>" AppliesTo="all" Category="Sample">   <RuleDesigner Sentence="Sting you want to appear on the workflow designer with one parameter %1 and a second parameter %2.">
        <FieldBind Field="ParameterOne" Text="First parameter text" DesignerType="TextArea" Id="1"/>
        <FieldBind Field="ParameterTwo" Text="Second parameter text" DesignerType="TextArea" Id="2"/>
        <Parameter Name="ParameterOne" Type="System.String, mscorlib" Direction="In" />
        <Parameter Name="ParameterTwo" Type="System.String, mscorlib" Direction="In" />

Now you should be able to see your activity when you are deigning a workflow in Sharepoint Designer, go to File > New > select the Sharepoint Tab > select Blank workflow. The designer is started up and when you reach the actual workflow design page (second page), you will have your activity on the Actions list, as shown bellow. Just add your activity, configure the parameters and that’s it!
Workflow designer

Here are some useful links: