Implementing error handling in the workflow adapter

To implement error handling in the custom workflow action adapter for a custom workflow action, you must configure the adapter to use the dependency properties for error handling added to the corresponding custom workflow activity. For more information about implementing error handling in workflow activities, see Implementing error handling in the workflow activity.

The ErrorHandling class, in the Nintex.Workflow.Activities.Adapters namespace, encapsulates the necessary validation, reading, and writing functionality for error handling. The ErrorHandling property of the NWActionConfig class instance for the workflow adapter is set to an instance of the ErrorHandling class. For more information about error handling in workflow actions, see Supporting error handling.

Note: The following examples refer to a custom workflow activity named CustomActivity, and a custom workflow adapter named CustomAdapter, for the purposes of describing how to implement error handling.

To add error handling to a workflow adapter

  1. In the GetDefaultConfig method of the workflow adapter class, instantiate and add the ErrorHandling class to the NWActionConfig class instance for the adapter. The workflow adapter class is the class in the workflow adapter that is derived from the GenericRenderingAction base class.

    public override NWActionConfig GetDefaultConfig(
      GetDefaultConfigContext context)
    {
      // Define the default configuration for the workflow adapter.
      NWActionConfig config = new NWActionConfig(this);
    
      // Set the ErrorHandling property for the default configuration
      // to a new ErrorHandling object.
      config.ErrorHandling = new ErrorHandling();
    
      // Finish defining the default configuration.
      
      // Return the default configuration.
      return config;
    }
    
  2. In the AddActivityToWorkflow method of the workflow adapter class, invoke the AssignTo method of the ErrorHandling class to assign values from the workflow adapter to the dependency properties of the workflow activity.

    public override CompositeActivity AddActivityToWorkflow(
      PublishContext context)
    {
      // Get the configuration parameters for the workflow adapter, and then
      // instantiate the workflow activity.
      Dictionary<string, ActivityParameterHelper> parameters = 
        context.Config.GetParameterHelpers();
      CustomActivity activity = new CustomActivity();
    
      // Set the error handling values.
      if (context.Config.ErrorHandling != null)
      {
        context.Config.ErrorHandling.AssignTo(
          (Activity)activity,
          CustomActivity.CaptureErrorsProperty,
          CustomActivity.ErrorOccurredOutputProperty,
          CustomActivity.ErrorMessageOutputProperty,
          context);
      }
    
      // Finish adding the workflow activity to the workflow.
      context.ParentActivity.Activities.Add(activity);
      return null;
    }
  3. In the GetConfig method of the workflow adapter class, invoke the BuildFrom method of the ErrorHandling class to retrieve values from the dependency properties of the workflow activity to the workflow variables specified by the workflow adapter.

    public override NWActionConfig GetConfig(RetrieveConfigContext context)
    {
      // Read the properties from context.Activity and update the values 
      // in the NWActionConfig object.
      NWActionConfig config = this.GetDefaultConfig(context);
      Dictionary<string, ActivityParameterHelper> parameters = config.GetParameterHelpers();
    
      // Get the error handling values.
      config.ErrorHandling = ErrorHandling.BuildFrom(
        (Activity)activity,
        CustomActivity.CaptureErrorsProperty,
        CustomActivity.ErrorOccurredOutputProperty,
        CustomActivity.ErrorMessageOutputProperty,
        context.Variables);
    
      // Finish retrieving configuration values.
      return config;
    }

See Also

Concepts

Workflow activities

Workflow action adapters

Operations

Working with workflow actions

Working with workflow activities