Add metadata to a custom workflow activity

 

Applies To: Dynamics CRM 2013

The assembly that contains the custom workflow activity definition is annotated using the .NET attributes to provide the metadata that Microsoft Dynamics CRM uses at runtime to link your code to the workflow engine. For more information about .NET attributes, see Extending Metadata Using Attributes.

Before you start adding metadata to your custom workflow activity definition, ensure that you are aware of the Microsoft Dynamics CRM types and attributes that are supported for the custom workflow activities. For more information, see Process classes, attributes, and types.

In This Topic

Adding Input Parameters

Adding Output Parameters

Adding Input and Output Attributes for the Same Parameter

Additional Attributes

Adding the Execute Method

Adding Input Parameters

While specifying the input parameter in your workflow class, you can also specify a default value for the parameter. The following sample shows the definition of an input parameter.

[Input("DateTime input")]
[Default("2004-07-09T02:54:00Z")]
public InArgument<DateTime> Date { get; set; }

This input parameter is annotated with the .NET attribute Input. The InputAttribute class derives from the ParameterAttribute class, which takes a parameter (ParameterAttribute.Name) to specify the name of the input attribute. This name appears in the process form assistant in the Web application. This lets you map an attribute as an input parameter to the process.

In addition, you can make the input parameter required. For more information, see RequiredArgumentAttribute.

Adding Output Parameters

Output parameters are added in the same manner as the input parameters. The following sample shows the definition of an output parameter.

[Output("Money output only")]
[Default("23.3")]
public OutArgument<Money> MoneyOutput { get; set; }

This output parameter is annotated with the .NET attribute Output. The OutputAttribute class derives from the ParameterAttribute class, which takes a parameter (ParameterAttribute.Name) to specify the name of the output attribute. This name appears in the process form assistant in the Web application. This lets you map an attribute as an output.

Adding Input and Output Attributes for the Same Parameter

You can use the input and output attributes for the same parameter. In the following code example, IntParameter is the input as well as the output parameter.

[Input("Int input")]
[Output("Int output")]
[Default("2322")]
public InOutArgument<int> IntParameter { get; set; }

Additional Attributes

Some types, such as EntityReference and OptionSetValue, require additional attributes apart from the Input, Output, and Default attributes. The additional attributes are: ReferenceTarget and AttributeTarget. The following sample shows the definition of a parameter of the EntityReference type.

[Input("EntityReference input")]
[Output("EntityReference output")]
[ReferenceTarget("account")]
[Default("3B036E3E-94F9-DE11-B508-00155DBA2902", "account")]
public InOutArgument<EntityReference> AccountReference { get; set; }

For a list of supported types and attributes, see Process classes, attributes, and types.

Adding the Execute Method

Your custom workflow activity must have an Execute method, as shown in the following example.

protected override void Execute(CodeActivityContext context)
{
   if (AccountReference.Get(context).Id != new Guid("3B036E3E-94F9-DE11-B508-00155DBA2902"))   
      throw new InvalidPluginExecutionException("Unexpected default value");
}

See Also

Custom workflow activities (workflow assemblies)
Custom workflow activities (workflow assemblies)
Create a custom workflow activity
Use the IOrganization web service in a custom workflow activity
Sample: Create a custom workflow activity
Process classes, attributes, and types