When creating workflow, SharePoint designer supports out-of-box actions which can be easily used. Examples are Sending email, Creating item in List of same site, Log to history list, etc. Below are set of actions provided in Sharepoint designer:
Workflow Actions Out-of-box
SharePoint Designer supports only a subset of the workflow activities available from the workflow foundation. The two most notable workflow activities that SharePoint does not support
are the WhileActivity, which is responsible for looping, and the ReplicatorActivity, which is responsible for iterating through a collection. Other activities, though supported, have limited functionality. For instance, the LogToHistoryActivity, which is used
to log messages to the Workflow History list, cannot write to the
Other Data field; therefore, messages from a SharePoint Designer–created workflow sent to the Workflow History list are capped at 256 characters.
If the limitations of SharePoint Designer are too restrictive, Visual Studio is the answer. With Visual Studio, you have complete access to the capabilities of the SharePoint Workflow host and workflow runtime.
The designer in Visual Studio allows for looping and iteration—the two key reasons why most solutions require a Visual Studio workflow.
We need to go for creating SharePoint Custom Workflow activity when SharePoint designer does not support out-of-box inbuilt actions for workflow. We had requirement to add/create new item in sub site's list
when workflow is triggered. SharePoint designer workflow actions support adding item in same site list but when it comes to adding item in sub site list it doesn't support, so we need to create SharePoint Custom Workflow activity.
Let's see how can we create Custom Workflow Activity:
Once the project is configured, we will create the activity code as shown below:
Creating the Activity Code
- You now have a SharePoint solution with the proper references set so that you can write an Activity. It is time to add the class and the first bit of code.
- Add a new empty Class file to the project. In my case I given Class Name is “CustomSubsSiteAction” and that class Inherit with “Activity” Class.
Sharepoint Creating Custom Activity |
In order to allow properties to be passed in from SharePoint designer, you have to set up Dependency Properties.
2. Add a Property and Dependency Property for values that will come in from the Workflow. Below is code:
When your activity starts, the Execute method is fired. This is where you will do the work in the Activity. So when can override Execute Method and Perform ours Operation.
But If you want to Access Current Item Like: List ID, List Item, Current Web than add Dependency Property for that. For access current site Context than Register Property as shown in code below:
000ff;">static DependencyProperty __ListItemProperty = System.Workflow.ComponentModel.DependencyProperty.Register("__ItemID", typeof(int), typeof(CustomSubsSiteAction));
Sharepoint - Override Execute method of Action |
Now,In order to get Action in the Sharepoint designer in Workflow actions:
In order for SharePoint designer to know about the Activity, we have to add a special XML file to the Workflow folder in the SharePoint hive.- Right-click on the Project and select Add -> SharePoint Mapped Folder…”
Adding Action to Sharepoint |
From the folder list, select “TEMPLATE/1033/Workflow“
Sharepoint Mapped Folder |
Custom Actions XML |
Assembly="CustomSubsSiteAction, Version=1.0.0.0, Culture=neutral,PublicKeyToken=7341b1706fa0e582"
AppliesTo="all" Category="Cross Sub-Site List">
Deploying & Register your Namespace for Authorization
Deploy the solution & to register Custom Activities to Webapplication's Web.Con;/Actions>Than Restart IIS.
Open run and just write IISreset and Ok.
Now Open Sharepoint Designer 2010 & Go to workflow
Sharepoint Custom workflow Action |