Activity type parameters
Activity parameters are properties that allow custom values to be passed into an activity. Activity parameters are made up of:
-
A public property in an activity type class, for example:
RequestResponseusing Sitecore.Xdb.MarketingAutomation.Core.Activity; using Sitecore.Xdb.MarketingAutomation.Core.Processing.Plan; using Microsoft.Extensions.Logging; namespace Documentation.Examples { public class DoNothingActivity : IActivity { public IActivityServices Services { get; set; } // Parameters public string NoReplyAddress { get; set; } public DoNothingActivity() { } public ActivityResult Invoke(IContactProcessingContext context) { // This activity does nothing return new SuccessMove(); } } }
-
A parameter item under the activity type descriptor. For example:
Setting an activity type parameter
The following steps are performed by the Marketing Automation UI.
Activity parameters are set by the Automation Plan Definition Manager. If an AutomationActivityDefinition
uses a the DoNothingActivity
type, you can pass in an optional NoReplyAddress
.
The following example assumes that the descriptor item ID of the DoNothingActivity
is {56632708-510a-46fd-995d-6a4a709e90d4}
. Parameters are passed into the Parameters
dictionary as shown:
var newActivity = new AutomationActivityDefinition
{
Id = Guid.NewGuid(), // ID of this instance
ActivityTypeId = Guid.Parse("56632708-510a-46fd-995d-6a4a709e90d4"),
Name = "Do nothing activity",
Parameters =
{
{ "NoReplyAddress", "[email protected]" }
}
};
In this example, the NoReplyAddress
parameter is hardcoded. If you were building a UI to create automation plans, you would use the Activity Type Descriptor Locator API to get a list of all available parameters for a particular activity type and prompt the user to supply a value.
Get all activity type parameters
Use the Activity Type Descriptor Locator API to retrieve all available parameters for a particular activity type. The following example demonstrates how to get the key and name of every parameter for a particular activity type:
using System;
using Sitecore.Xdb.MarketingAutomation.Locators.AutomationPlans;
using Sitecore.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using System.Globalization;
namespace Documentation.Examples
{
public class Locators
{
public void LocatorsExample()
{
var locatorService = ServiceLocator.ServiceProvider.GetService<IActivityDescriptorLocator>();
var activityTypeDescriptorId = Guid.Parse("{56632708-510a-46fd-995d-6a4a709e90d4}");
var descriptor = locatorService.GetDescriptor(activityTypeDescriptorId, CultureInfo.InvariantCulture);
foreach (var parameter in descriptor.Parameters)
{
var key = parameter.Key; // Exact name of property
var name = parameter.Name; // Human-readable name
}
}
}
}