Activity Type Descriptor Locator API

Current version: 9.2

You can use the Activity Type Descriptor Locator API (Descriptor Locator API) to retrieve descriptors by ID or by classification. Use Sitecore’s service locator to get an instance of the Descriptor Locator API:

RequestResponse
using Sitecore.DependencyInjection;
using Sitecore.Xdb.Locators.AutomationPlans;
using Microsoft.Extensions.DependencyInjection;

namespace Documentation
{
    public class ActivityLocatorService
    {
        public void Example()
        {
            var locatorService = ServiceLocator.ServiceProvider.GetService<IActivityDescriptorLocator>();
        }
    }
}
Note

The Activity Type Descriptor Locators API is separate from the Marketing Operations API. Activity type descriptors represent a registration of an implemented type and are created by developers. Definitions managed by the Marketing Operations API are created by marketers.

Get activity type descriptor by ID

Use the .GetDescriptor() method to get a descriptor by ID. The ID corresponds to the ID of the descriptor item in Sitecore.

RequestResponse
using Sitecore.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using System;
using Sitecore.Xdb.MarketingAutomation.Locators.AutomationPlans;
using Sitecore.Xdb.MarketingAutomation.Locators.AutomationPlans.Model;

namespace Documentation
{
    public class ActivityLocatorCreate
    {
        public void Example()
        {
            var locatorService = ServiceLocator.ServiceProvider.GetService<IActivityDescriptorLocator>();

            var locatorId = Guid.Parse("{743489A2-8BD0-49ED-B284-5534AC59685A}"); // Item ID

            IActivityDescriptor descriptor = locatorService.GetDescriptor(locatorId, new System.Globalization.CultureInfo("dk"));
        }
    }
}

Get all activity type descriptors

Use the .GetAllDescriptors() method to get all activity types. The results can be paginated.

RequestResponse
using Sitecore.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using System;
using Sitecore.Marketing.Core;
using Sitecore.Xdb.MarketingAutomation.Locators.AutomationPlans.Model;
using Sitecore.Xdb.MarketingAutomation.Locators.AutomationPlans;

namespace Documentation
{
    public class ActivityLocatorGetAll
    {
        public void Example()
        {
            var locatorService = ServiceLocator.ServiceProvider.GetService<IActivityDescriptorLocator>();

            // Get first 200 descriptors with 'DK' culture
            ResultSet<IActivityDescriptor> descriptors = locatorService.GetAllDescriptors(new System.Globalization.CultureInfo("dk"), 1, 200);

            // Cycle through results
            var firstPage = descriptors.DataPage;
            var total = descriptors.Total;

            foreach (var descriptor in firstPage)
            {
                var nameOfDescriptor = descriptor.Name;
            }

        }
    }
}

Get activity type descriptor by classification

Use the .GetDescriptorsByClassification() method to get all activity type descriptors with a particular taxonomy value assigned.

RequestResponse
using Sitecore.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using System;
using Sitecore.Marketing.Core;
using Sitecore.Xdb.MarketingAutomation.Locators.AutomationPlans;

namespace Documentation
{
    public class ActivityLocatorGetByClassification
    {
        public void Example()
        {
            var locatorService = ServiceLocator.ServiceProvider.GetService<IActivityDescriptorLocator>();

            var taxonomyId = Guid.Parse("{340062A7-9F50-4CE1-8A53-DA3F6A23B73A}"); // Activity functional type taxonomy
            var taxonomyValue = Guid.Parse("{144EEBB0-1CD1-4DEA-95A7-04D24D16FDC0}"); // Marketing action value

            var descriptors = locatorService.GetDescriptorsByClassification(new System.Globalization.CultureInfo("dk"), taxonomyId, taxonomyValue, 1, 20);

            var pageData = descriptors.DataPage;

            foreach (var descriptor in pageData)
            {
                var name = descriptor.Name;
            }
        }
    }
    }
Important

For performance reasons, you must supply the root taxonomy Guid as well as the value Guid.

Do you have some feedback for us?

If you have suggestions for improving this article,