Add metadata to a custom workflow activity

 

Updated: November 29, 2016

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

The assembly that contains the custom workflow activity definition is annotated using the .NET attributes to provide the metadata that Microsoft Dynamics 365 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 365 types and attributes that are supported for the custom workflow activities. More information: see Process classes, attributes, and types

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

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.

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; }

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.

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");
}

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright

Community Additions

ADD
Show: