Skip to main content

Add a complex parameter to a custom activity

Abstract

How to add a complex parameter containing an object or a collection of objects to a custom activity in Data Exchange Framework.

You might have an activity editor that returns an object or a collection of objects instead of a single text or number field. In this case, you must create a custom C# type that matches the complex editor data.

An activity editor with complex parameters might, for example, look like this:

Custom activity editor with complex activity

In this editor you can select more than one option. In the example, both Option 1 and Option 2 have been selected, and the editor's serialize method returns a JSON object like this:

serialize(): any {
  // ... some logic to get selected options
    return {
      Collection: [{
          Name: 'Option 1',
          Id: '1'
      }, {
          Name: 'Option 2',
          Id: '2'
      }];
    };
}  

To implement an action to handle the type:

  1. In a custom C# type, create an activity implementation class like this:

    namespace CustomActivity
    {
      public class MyCustomActivity : IActivity
      {
          public List <TestClass> Collection { get; set; }
      }
    }
  2. Create a complex type implementation like this:

    namespace CustomActivity
    {
      public class TestClass
      {
          public string Name { get; set; }
          public int Id { get; set; }
      }
    } 
  3. Generate your plugin and deploy it to Sitecore.

  4. In the content tree, navigate to your custom activity item. Add a new parameter item by right-clicking Parameters, and in the Insert menu, click Activity Parameter.

  5. On the Content tab, in the Editor section, fill in the following values:

    Field

    Value

    Editor ID

    B5DD8B01-C09A-4FDA-8900-758C84171743

    Editor Parameters key (first field)

    ObjectType

    Editor Parameters value (second field)

    Enter the type you defined in your activity class. For example, System.Collections.Generic.List`1[[CustomActivity.TestClass, CustomActivity]]

    custom activity editor
  6. Save the changes.