Posted by: R Manimaran | February 17, 2011

SharePoint Designer 2007 workflow : Creating Custom Action – Recycle Item

SharePoint Designer 2007: Creating Custom Action – Recycle List Item

SharePoint Designer 2007 contains some preset of actions that can be used in the Designer workflows. Suppose if we need to implement our own logic, then we can achieve this by creating custom actions.

We have the actions to delete the item permanently, but there is no action to move the item to the recycle bin. Here I have created a custom action to achieve this.

Follow the below steps to create a Recycle Item custom Action.

1. Create a New Project of type Workflow Activity Library in Visual Studio 2008.

2. Delete the default activity Activity.cs.

3. Add a new Activity item and name it as RecycleItem

4. Add reference to the following namespaces

a. Microsoft.SharePoint

b. Microsoft.SharePoint.WorkflowActions

5. If the activity is inherit from SequenceActivity change it to inherit from Activity

6. Now Define the Properties that are going to be used.


public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(DeletePreviousVersions));
[DescriptionAttribute("__Context")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Optional)]
public WorkflowContext __Context
{
get
{
return ((WorkflowContext)(base.GetValue(DeletePreviousVersions.__ContextProperty)));
}
set
{
base.SetValue(DeletePreviousVersions.__ContextProperty, value);
}
}
public static DependencyProperty ListIdProperty = DependencyProperty.Register("ListId", typeof(string), typeof(DeletePreviousVersions));
[DescriptionAttribute("ListId")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
public string ListId
{
get
{
return ((string)(base.GetValue(DeletePreviousVersions.ListIdProperty)));
}
set
{
base.SetValue(DeletePreviousVersions.ListIdProperty, value);
}
}
public static DependencyProperty ListItemProperty = DependencyProperty.Register("ListItem", typeof(int), typeof(DeletePreviousVersions));
[DescriptionAttribute("ListItem")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
public int ListItem
{
get
{
return ((int)(base.GetValue(DeletePreviousVersions.ListItemProperty)));
}
set
{
base.SetValue(DeletePreviousVersions.ListItemProperty, value);
}
}

7. Override the Execute method and do the business logic.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
SPList list = this.__Context.Web.Lists[new Guid(this.ListId)];
list.GetItemById(this.ListItem).Recycle();
return ActivityExecutionStatus.Closed;
}

8. Create a strong name for the assembly by signing the Project.

9. Build the solution.

10. Deploy the assemnly in the GAC.

11. Navigate to the root port directory of the SharePoint Site for which the activity is created located in “C:/inetpub/wwwroot/wss/virtualdirectories/” and search for “web.config” file. These xml files contain lists of authorized types that can be used for that server port.

12. Add the authorizedType tag element for the new assembly as below


<authorizedType Assembly="CustomActions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5f6a90160d0f9770" Namespace="CustomActions"  TypeName="*" Authorized="True" />

13. To show our actions in the SharePoint Designer, we need to modify the WSS.Actions file located in %12Hive%/Template/1033/Workflow

%12Hive% – “C:/Program Files/Common Files/Microsoft Shared/web server
extensions/12”

14. This is the file from which all the actions are get loaded in to the SharePoint Designer.

15. Add our action element just before </Actions> tag.

<Action Name="Move Item to Recycle" ClassName="CustomActions.RecycleItem" Assembly="CustomActions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5f6a90160d0f9770" AppliesTo="all"Category="Custom Actions">

<RuleDesigner Sentence="Recycle item in %1">

<FieldBind Field="ListId,ListItem" Text="this list" Id="1" DesignerType="ChooseListItem" />

</RuleDesigner>
 <Parameters>

<Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext" Direction="In" />

<Parameter Name="ListId" Type="System.String, mscorlib" Direction="In" />

<Parameter Name="ListItem" Type="System.Int32, mscorlib" Direction="In" />    </Parameters>

</Action>

16. Save the Wss.Actions file.

17. Do an IISRESET.

18. Open the SharePoint Desiger and open the site where you want to place the action.

19. Create new workflow and select the list where the workflow needs to be associated.

20. Click the Next button. Click the Actions drop down and select the category “Custom Actions”

21. Select the Action “Move Item to Recycle”

22. Click add. Now choose the item where the workflow needs to associate. Choose the current item.

23. Once the Workflow gets associated, move to the List and run the workflow on an item.

24. Click the Start button on the screen for initiate the workflow

25. Once the workflow completed, the corresponding List item get deleted and moved to Recycle bin.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: