ExecuteSqlScalarWithDeploy sample
The ExecuteSqlScalarWithDeploy sample provides an example of deploying an existing Nintex Workflow 2013 custom workflow action by using a SharePoint 2013 feature with a custom event receiver.
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 is the same custom action provided in the ExecuteSqlScalar sample. The samples are provided so that you can perform a side-by-side comparison, to better understand how the SharePoint feature interacts with both SharePoint 2013 and Nintex Workflow 2013, as well as the custom workflow action itself, when deployed. For more information about the ExecuteSqlScalar sample, see ExecuteSqlScalar sample.
The SharePoint solution package project includes a SharePoint feature, named Deploy.feature, which handles the deployment of the Execute SQL Scalar 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.
-
Using the sample
You can either deploy the sample to a local SharePoint site directly from Visual Studio, or you can publish the sample to a SharePoint solution package (.wsp) file that can be deployed to a SharePoint site. Once the sample is deployed, the custom workflow action is represented by the Execute SQL Scalar Action feature, which you can then activate on the web application of your choice. The following screen shot illustrates how the feature is displayed in the Manage Web Application Features dialog of SharePoint Central Administration:
See Also
Concepts
Operations
Working with workflow activities