Share via


Add metadata to a custom workflow activity

 

Applies To: Dynamics CRM 2015

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’re aware of the Microsoft Dynamics CRM types and attributes that are supported for the custom workflow activities. More information: see Process classes, attributes, and types

In This Topic

Add input parameters

Add output parameters

Add input and output attributes for the same parameter

Additional attributes

Add the Execute method

Add 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. More information: RequiredArgumentAttribute

Add 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.

Add 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.

Add 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

© 2016 Microsoft. All rights reserved. Copyright