DeployWorkflowActionWithFeature sample
The DeployWorkflowActionWithFeature sample provides an example of implementing a simple SharePoint 2013 solution package to deploy a custom workflow action.
Overview
The sample represents a SharePoint 2013 solution package, in which a single feature, scoped to a web application, performs the following tasks:
-
Registers the custom workflow action with Nintex Workflow 2013
-
Enables the custom workflow action for use with the Workflow designer, within the SharePoint farm
-
Adds necessary entries in the web.config configuration file for the web application, to authorize the custom workflow activity included with the custom workflow action for use in SharePoint declarative workflows
The custom workflow action included with this sample writes log entries to the SharePoint ULS logs. The folder structure of this sample is driven by the folder structure used by a typical custom workflow action in Nintex Workflow 2013. For more information about creating custom workflow actions, see Creating workflow actions.
The SharePoint solution package project includes a SharePoint feature definition, named DeployActionExample.feature, which handles the deployment of the custom workflow action. The feature uses an event receiver to handle the following events:
-
This method is called when the feature is activated. When called, it performs the following actions:
-
Retrieves the contents of the action definition (.nwa) file for the custom workflow action, and uses the contents to register the custom workflow action with the Nintex Workflow 2013 configuration database.
The ActivityReference object, from the Nintex.Workflow namespace, that represents the custom workflow activity included in the custom workflow action is instantiated and populated from the action definition file, and then the FindByAdapter method of the ActivityReferenceCollection object for the current web application is invoked to see if the activity has been previously registered.
If it has been previously registered, then the UpdateActivity method is invoked to update the information about the activity in the configuration database. Otherwise, the AddActivity method is invoked to add the information to the configuration database.
-
Modifies the web.config file for the web application to install the custom workflow activity to the collection of authorized activity types for the web application.
The type name and assembly name of the custom workflow activity is first extracted, using the ExtractNamespaceAndClassname static method of the Utility class, from the Nintex.Workflow namespace, and then the InstallAuthorizedWorkflowTypes static method of the AuthorisedTypes class, from the Nintex.Workflow.Administration namespace, is used to add the type name and namespace name to the collection of authorized workflow types for the current web application.
-
Activates the custom workflow activity for the SharePoint farm, so that the Workflow designer can access and display the custom workflow action.
An ActivityActivationReference object, from the Nintex.Workflow namespace, is instantiated based on the information specified in the previous steps, and then the AddOrUpdateActivationReference method is called to activate the custom workflow activity.
-
-
This method is called when the feature is deactivated. When called, it backs out the changes made by the FeatureActivated event.
The method attempts to instantiate an ActivityReference object for the custom workflow activity, by invoking the FindByAdapter method of the ActivityReferenceCollection object for the current web application. If the activity exists, the method performs the following steps:
-
Removes the action definition from the Nintex Workflow 2013 configuration database.
If the current feature isn't activated in any other web application on the SharePoint farm, the action definition for the custom workflow activity is removed from the configuration database by invoking the RemoveAction method of the ActivityReferenceCollection object.
-
Removes the web.config entries that authorized the custom workflow activity for use in the web application.
The method checks each web.config modification found in the collection of SPWebConfigModification objects for the current web application, in which the owner of the SPWebConfigModification matches Nintex Workflow 2013. If the authorized workflow type of a matching modification matches the type of the custom workflow activity, the Remove method of the SPWebConfigModification object is invoked to remove the modification from the collection.
-