Adding Activities to SPD


GabeEilene Hey everyone,

Eilene Hao and Gabe Hall here, a program manager and developer on the SPD workflow team; nice to meet you! Today we’d like to answer one of our most frequently asked questions: adding activities into the SPD workflow designer. There’s a more detailed whitepaper describing this in the MOSS SDK’s ECM Starter Kit, but we thought it might be good to give you guys a quick summary, show you another example and give you some tips and tricks to help solve common issues.:)

How does it work?

Before we start with the walkthrough, let’s do a quick rundown of how the SPD workflow designer interacts with actions in SharePoint, so that what we do might make a little more sense.;)

All the actions you see in the SPD workflow designer are activities that live in a DLL on the SharePoint box (e.g. Microsoft.SharePoint.WorkflowActions.dll). There’s a .ACTIONS XML file in the SharePoint TEMPLATE directory on the local file system that describes how to display each of that DLL’s activities in a sentence form and bind parameters to the activity’s properties. SPD reads all .ACTIONS files in the directory, then shows all the activities in the designer and pushes the data you enter down into the activity’s properties.

So how do you “import” the activity?

  1. Create an activity with promoted properties in Visual Studio 2005 called CreateACLTask. This activity is similar to the “Assign a ToDo item” action, except it only assigns to one user, and it restricts permissions on the task so that only the user it’s assigned to can see or edit it.
  2. Deploy the activity DLL to the Global Assembly Cache (GAC). This will allow SharePoint to load the activity code you wrote.
  3. Add the DLL to the web.config files. I.e. tell SharePoint that your new activity is safe to use. 🙂
  4. Create and deploy a .ACTIONS file for the activity to describe the sentence. SPD can read this to know what sentence to create and how to link that sentence into the activity.

Step 1: Creating the activity

This’ll be a pretty basic activity. In Visual Studio, hit File->New->Project and select a workflow activity library. For this action, we’re going to create a task, wait for user to edit the task, and then complete the task. So just 3 activities in sequence: CreateTaskWithContentType, OnTaskChanged, and CompleteTask. Fill out the properties like you normally in a VS workflow.

What’s special about the activity we’re building is that it uses the SpecialPermissions property on CreateTaskWithContentType. This property takes a hashtable of user-permission pairs (e.g. “DOMAIN\john”, SPRoleType). If you bind a hashtable to SpecialPermissions, CreateTaskWithContentType will strip out all existing permissions and only add permissions for each pair you add to the hashtable (if you don’t bind anything to it, it inherits permissions from the task list). So if you wanted only the user the task was ‘assigned to’ to see or edit, you would just say: hashtable.Add(“DOMAIN\john”, SPRoleType.Contributor).

Of course, in this case, we don’t know who this assignee is; he’s specified in SPD, so how do we get that property from the designer?

Enter promoted properties. Promoted properties are properties that are exposed externally to a parent workflow or activity. When SPD generates the parent workflow, the parent workflow passes values through this property into the child activity. Here, we want to get the assignee of the task, so we create a “Dependency Property” with a handy code snippet and name it “Assignee”.

So we bind all the properties on our activity, and now in the CreateTask handler, we’ll use the following code:

private void CreateTask(object sender, EventArgs e)
{
    taskId = Guid.NewGuid();
    taskProperties.AssignedTo = Assignee; //Assignee demoted from SPD!
    taskProperties.Description = “Complete the task”;
    taskProperties.Title = “You have a new task”;
    specialPermissions.Add(Assignee, SPRoleType.Administrator);
}

The last piece of info we need in this activity is the content type for the task. A content type for a workflow tasks is what determine which aspx form to use for editing a task. Have you ever seen the New Task dialog that pops up in SPD when you add an “Assign a Todo” action? This dialog actually creates a new task content type along with an .aspx form to go with it.

So to get the content type, we just need to bind CreateTaskWithContentType’s ContentTypeId property to a promoted property. Rather than use a snippet, this time we can just select create a new property directly from the property binding dialog:

https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/sharepointdesigner/WindowsLiveWriter/AddingActivitiestoSPD_FE79/clip_image002.jpg

Next, add whatever code you want, and with Assignee and ContentTypeId promoted, we can now deploy it so that you can use it in SPD.

Step 2 and 3: Deploying the DLL and adding it to the authorized types list

Once we’re done with our code, we can compile it and get our DLL. Our DLL should go into the server/web front end’s GAC (%windir%\assembly) so that SharePoint can find and load the activity.

But before SharePoint will run the activity, it has to know that our new dll’s types are safe and trusted so we need to add it to the web.config file. Updating the config file’s authorized types means this activity can be used in declarative workflows in WSS (the workflow equivalent of ‘safe for scripting’). To open this file:

  1. Open the IIS console.
  2. Find the web site that is your SharePoint web under the “Web sites” node and select it.
  3. Right click and choose “Open”.
  4. In the folder window, open the web.config file.

In web.config, browse to the bottom section and look for <System.Workflow.ComponentModel.WorkflowCompiler>. Inside that tag there should be an <authorizedTypes> section and an entry for each set of types. Add your type with the following line of XML:

<authorizedType Assembly=”CreateACLTask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7114224e81918c16″ Namespace=”CreateACLTask” TypeName=”Activity1″ Authorized=”True” />

Step 4: Creating and adding a .ACTIONS file

Now that our activity can be used by WSS, we have to add it to the actions that SPD can author by adding an entry in a .ACTIONS file. It’s a relatively straightforward XML file; however it has a few moving parts so we will just highlight the important aspects today.

Go to your WSS install directory (typically Program Files/Common Files/Microsoft Shared/web server extensions/12), and find the template/1033/workflow folder. (replace 1033 with the proper language ID if it’s not an English server). Place the following in a new file with the name ‘CreateACLTask.actions’:

<?xml version=”1.0″ encoding=”utf-8″?>
<WorkflowInfo>
  <Actions Sequential=”then” Parallel=”and”>
    <Action Name=”Assign To-do Item with restricted permissions” ClassName=”CreateACLTask.Activity1″ Assembly=”CreateACLTask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7114224e81918c16″ AppliesTo=”all” CreatesTask=”true” Category=”Task Actions”>
      <RuleDesigner Sentence=”Assign %1 to %2 with restricted permissions”>
        <FieldBind Field=”Title,ContentTypeId” DesignerType=”Survey” Text=”a to-do item” Id=”1″/>
        <FieldBind Field=”Assignee” DesignerType=”SinglePerson” Text=”this user” Id=”2″/>
      </RuleDesigner>
      <Parameters>
        <Parameter Name=”ContentTypeId” Type=”System.String, mscorlib” Direction=”In” />
        <Parameter Name=”Assignee” Type=”System.String, mscorlib” Direction=”In” />
      </Parameters>
    </Action>
  </Actions>
</WorkflowInfo>

Essentially, this is a copy of the “Assign To-do item” entry in WSS.ACTIONS with a couple minor changes to the sentence, assembly, and bindings. Now, just do one IISReset and open SPD to create your new locked-task workflows! 🙂

Tip: the most common pitfall is adding a .ACTIONS or web.config entry which doesn’t exactly match your custom DLL. If you find that the action shows up in SPD, but nothing appears when it is selected, verify that the entries you’ve made match the activity class exactly. If a particular binding won’t change, make sure your .ACTIONS field bindings match the promoted properties in your DLL.

In Office 2007, building actions for SPD can be easier and faster than authoring a workflow in Visual Studio. We’ve attached the sample files if you’re interested in taking a closer look.

Good luck and we hope this helps :)!

Eilene and Gabe

CreateACLTask.zip


Comments (42)

  1. SharePoint Designer Team Blog に、Visual Studio 2005 で開発したワークフローのカスタムアクティビティを、SharePoint Designerのワークフローに登録する方法が公開されました。

  2. Mark says:

    FWIW, there’s an extremely small typo in the article.  When you say "find the templates/1033/workflow folder", "templates" should be "TEMPLATE".  At least on my box.  🙂

    Other than that, this article is the best.

  3. Gabe says:

    Ahh good catch, thanks!

  4. Hi folks, it’s Gabe Hall again with a quick tip you can use when developing workflow activities on WSS

  5. Three good references to get you started: HOW TO: Create a custom Windows Workflow Activity and make

  6. Stefan says:

    Great! This helps a lot…

    Could you please post a list of all available Designertypes and a little "howto" of how to build a custom designertype?

    Bye

    Stefan

  7. Q: In .xoml file of workflow I’ve found some intresting line:

    <ns0:FindActivity ListId="{}{DD89B2BF-CB7D-4E2E-BF0A-5883D63B442C}" x:Name="ID83" FieldName="Author" ……cut…../>

    Parameter ListID – it’s public property of FindActivity class (I’m thinck so).

    And questions is: the first pair of {} – that is? Does this the WebID or not?

    If that is’nt WebID then what is?

    PS Sorry for my English.

  8. spdblog says:

    Freeman,

    WebID is implied by the workflow’s web.  It isnt passed into the FindActivity.  ListID can be a name of a list or a GUID.  The first pair of {} is not used to determine web or list.

    Stefan,

    That is a great topic for future posts.  I’ll add it to the list.

    -Gabe Hall

  9. spdblog,

    Thanks. Why i’am ask for – i’m want to use linked List for FindActivity from another Web (but same Site scope)

  10. Is there a way to deploy your new "authorizedType" to the Web.config (similar to adding a safe controls entry) using a SharePoint Solution?

    I would like to allow deployment of new SPD Actions via SharePoint Solution deployment.

    Thanks!

  11. Raghu Iyer says:

    Excellent, well though there are number of other articles on custom activity but i was stuck in an issue which ur "pitfall" section took care.

    Thanks,

    http://metahat.blogspot.com

  12. Philipp says:

    Cool, with every new article there is one new detail… 😉

    But as stefan allready asked. Is there a list with all available designer types? Would be a great insight…

    And if there is a way to extend or buid custom ones, even better.

  13. こんにちは。 方法を掲載しようと思いましたが、既にチュートリアルとサンプルのダウンロードが可能なページがありますのでご紹介します。(下記リンク) Adding Activities to SPD (Microsoft

  14. Stefan says:

    Hi all,

    I have found the wssacions.xsd at http://johnholliday.net/download/wssactions.xsd. There you can find all available Designertypes:

     <xs:enumeration value="ChooseDocLibItem" />

     <xs:enumeration value="ChooseListItem" />

     <xs:enumeration value="CreateListItem" />

     <xs:enumeration value="Date" />

     <xs:enumeration value="Dropdown" />

     <xs:enumeration value="Email" />

     <xs:enumeration value="Integer" />

     <xs:enumeration value="FieldNames" />

     <xs:enumeration value="ListNames" />

     <xs:enumeration value="Operator" />

     <xs:enumeration value="ParameterNames" />

     <xs:enumeration value="Person" />

     <xs:enumeration value="SinglePerson" />

     <xs:enumeration value="StringBuilder" />

     <xs:enumeration value="Survey" />

     <xs:enumeration value="TextArea" />

     <xs:enumeration value="UpdateListItem" />

     <xs:enumeration value="WritableFieldNames" />

    But i still need help for designing custom designertypes.

    HELP!!

    Bye

    Stefan

  15. has says:

    I have checked and double checked everything, but I still can’t this to work.  My activity is showing up is SPD, but nothing is showing up after I select it.  Can anyone tell me what I might be doing wrong?

    I have made sure that all the entries match, but I still can’t seem to make it work.

  16. Paul Galvin says:

    Great article!

    I am able to deploy my custom action and it shows up in SPD.  I can create a workflow and select the action.  However, when I enter data into one of the fillin fields and press return, the value does not "stick".  I’m sure there is some obvious thing I"m doing wrong, but it appears consistent with this and other workflow examples I have found.  Any help is appreciated.

    Thanks!

  17. FredCote says:

    Me too same thing happen to me, I can see it in Custom Activities I got my Move File Activity but when I select it nothing show

  18. Jon Frank says:

    I’d been having the same problem, where I add a custom activity to the .ACTIONS file, added the authroizedType to web.config, and properly deployed the DLL into the GAC and yet no text would show up in the Workflow Designer when I selected my custom activity. After checking and rechecking, I took a stab in the dark on the off chance it might work.

    As it turns out it did. The problem seemed to involve an extra space in the Assebly string in either web.config or the .ACTIONS file.

    I’d had ‘Assembly="Examples.SampleActivity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=abcedf1234567890 "’ in both web.config and WSS.ACTIONS. Removing the extra space after the PublicKeyToken’s value in both locations fixed the problem. I imagine this is simply a parsing bug in SPD, since that space really shouldn’t mess anything up, but fortunately it’s a simple fix.

    Hopefully this saves someone from the hours of frustrating errorless debugging that I had to go through. Take care,

    -Jon

  19. Edgardo says:

    Hi,

    nice article, but I still have a problem. Could someone explain me, how can I read the workflow’s initiator name and save it in a variable. I need this as an activity in SP Designer. I must assign a task (collect data) to the workflow initiator, but I far as I know, there is no way OOTB. I have not figured any workaround and this is very urgent.

  20. Pantera71 says:

    Hi,

    it seems that my previous comment (question) didn’t get posted.

    Within a workflow I need to assign a task to the task initiator. This seems pretty trivial, but there is no way of doing it in SPD with OOTB activities. I want to write an activity in which I just read the initiator’s name and the save it a variable. How can I create such an activity in I pass an output variable the string?

    Thank you in advance!

    -Edgardo

  21. Ismail says:

    Question regarding Pitfall discussed here:

    I have been trying to use  a simple Activity(from activity library) from two days.

    As explained by other, even i have the same problem

    I am able to see custom activity, but nothing happens in SPD.

    I made sure that there is no discrepancy in .ACTIONS and web.config file.

    Please help.

  22. Hi, I’m Phil Allen, a developer with the SharePoint Designer team who works primarily on Workflow. Today

  23. Chanda says:

    Thanks for the article!  Unlike many others this didn’t skip the info in Step 2 that was needed to deploy the assembly.

    For those that are running into the issue that the text/sentence doesn’t show up when you select the action in SPD, don’t overlook the step of doing an IISRESET on the server once you have modified the .ACTIONS  and the web.config files – this fixed the issue for me.

  24. Rich Rockwell says:

    I have the same question as Edgardo – how can I capture the name of the initiator of a workflow to use it in the workflow in SharePoint Designer, such as in a variable.

  25. Susangita says:

    In a document libraray ,for the record while clicking delete i am invoking  a custom  approval workflow .

    If the document has been approved then only it ‘ll be deleted.

    In my event handler class I am desebaling the delete event and then starting my workflow  & in my workflow  code while approving i am trying to delete the record .But it’s showing error that u r not supposed to delete it.

    Is there any way to solve this problem?

  26. Hi there, I’m Jordan Hull, a Software Development Engineer in Test on the SharePoint Designer Workflow

  27. Viji says:

    For people who are still having issues with nothing happening in SPD when choosing the custom activity, here’s a pointer – I had the same issue and I figured the token in assembly tag should have space after the comma. What I mean is :

    Correct assembly string: Assembly="CustomWFActivity1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6117140bb48139dd"

    Incorrect assembly string : Assembly="CustomWFActivity1,Version=1.0.0.0,Culture=neutral,PublicKeyToken=6117140bb48139dd"

    Note the spaces after each comma in the correct string – this seems stupid, but this resolved the issue for me.

    And remember to do IISReset after ensuring the assembly token is the same in web.config and the actions file.

    Hope this helps someone.

  28. Robert says:

    Hello Eilene and Gabe:

    This is save my days, Thanks.

    An quick question, Do you have a try to make the workflow activity as a SharePoint solution package before? I wonder to know does possible to do that?

    Thanks

    -Robert

  29. DP says:

    Hi All,

    I was wondering if anyone had expiriensing the same issue. I’m using a code below to set the properties for the task, and it’s working just fine exept for AssignedTo field. In debug mode it shows the value for alll of the field, but when the task is created only Description and Title are showing up???

    Thanks in advance,

    DP

    Private Sub CreateTask(ByVal sender As System.Object, ByVal e As System.EventArgs)

           taskId = Guid.NewGuid

           taskProperties.Description = "Please Approve this Change Control Form"

           taskProperties.Title = "Change Control Form is waiting for your approval"

           taskProperties.AssignedTo = workflowProperties.Item("AssignedTo").ToString

           taskProperties.SendEmailNotification = True

    End Sub

  30. Baher says:

    hey there,

    i want to ask a question , i know it’s somewhat irrelivant to the subject but i couldn’t find anywhere else to ask, my problem is that when i want to create a website i choose Fie -> New -> Web Site and then when it shows me three options to choose from on the left  General , Templates, and SharePoint Templates.

    When i select the General one three options appear , but when i select either one of the two options nothing appear , i am new to sharepoint and i don’t have any clue what to do , so your help will be very appreciated. thanks in advance.

    Baher.

  31. La conception et le développement de workflow sous SharePoint peut des fois donner le sentiment d’un

  32. Erik says:

    Thank you very much Viji.

    You save my weekend

    Erik

  33. H says:

    As Edgardo and Pantera71 question

    How do you get the workflow’s initiator name and save it in a variable?

    And supplementary….

    Can this be done in Sharepoint Designer and if so how it’s such a basic simple requirement?

    Any help would be most gratefully received, it’s driving me nuts!!

    H

  34. Excllent Article!  Thanks for the zip of the code

    -Dave

  35. Sadly, it is not to be. We cannot send an email with attachments from a SharePoint Designer workflow

  36. Bhavik says:

    I cant open the default.aspx file in SPD HTML version.

    It does open in notepad but when selected SPD HTML as the default editor, it does nothing.

    Does anybody know what could be the issue?

  37. saro says:

    How can we send email to more than one people???

  38. Asif says:

    Hi All,

    I have succesfully create the custom activity, and add it to the sharepoint by update the webconfig in the root file and create the ACTION file.

    this activity is shown in the sharepoint designer -> Workflow Action list -> category All, but when i select that action the dialog box close but it not actually assign to the workflow.

    can any one help what mistake i m doing, i follow this article:

    http://moss2010.spaces.live.com/blog/cns!4299AAC7892465EB!169.entry?sa=117152009

    Thanks in advance

  39. Daniel says:

    Hi.

    Same problem, but just on one installation an other works fine. Is there any SPD Log or debug message to find the problem?

  40. Prasad says:

    I have custom activity which is working fine… However whenever I try to modify the workflow designer doesnt show this activity sentence. Whats wrong?

  41. Hi,

    I have created a custom activity where the project name is "WaitFormToBeClosed" and the class have the same name, when I add the activity to SPD and click finish I get an error:

    "errors were found when compiling the workflow.The workflow files were saved but can't be run"

    and the details are:

    (651,35).The type name "WaitFormToBeClosed" doesn't exist in the type "WaitFormToBeClosed.WaitFormToBeClosed"

    I added the dll to GAC and added it in authorized types in the web.config that exists in both IIS root and in Config folder and I couldn't figure out what may be the problem so kindly advise.

    Thanks in advance.

Skip to main content