Flow Steps and Rule Steps (Simple) Creating Custom Data Types
  • Updated on 11 Dec 2013
  • 2 minutes to read
  • Print
  • Dark
    Light

Flow Steps and Rule Steps (Simple) Creating Custom Data Types

  • Print
  • Dark
    Light

Summary
You can easily create new datatypes to be used in Decisions by creating classes in a class file project. This article will show you how to accomplish this.

*Note custom codes are located here: C:\Program Files\Decisions\Decisions Services Manager\Instances\Control\CustomReferences

Example
In this example, Visual Studio 2017 is the IDE that is being used. Create a new  Class Library project in Visual Studio. Download the  Decisions SDK by right clicking your project in the   Solution Explorer and go to  Manage NuGet Packages. Under the  Browse tab, search for  DecisionsSDK then install.

DecisionsSDK.png

Add  the following using statement to your project:  using System.Runtime.Serialization;

Create a public class for your data type and decorate this class with the following attribute: [DataContract]
Add public properties for each property you want on your class decorated with the following attribute: [DataMember]
After adding all the properties you want, add a public parameterless constructor.
Below is an example of code that follows these patterns:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using DecisionsFramework.ServiceLayer.Utilities;

namespace ClassLibrary_CreatingCustomDataTypes
{

    public class DataContractAttribute : Attribute { }
    public class DataMemberAttribute : Attribute { }

    [AutoRegisterNativeType]
    [DataContract]
    public class House
    {
        [DataMember]
        public string Color { get; set; }
        [DataMember]
        public int NumberOfRooms { get; set; }
        [DataMember]
        public DateTime DateBuilt { get; set; }

        public House() { }

    }
}

After you have written your classes, build your project, copy the compiled dll to C:\Program Files\Decisions\Decisions Services Manager\modules\Decisions.Local\ServicesDlls, and restart Service Host Manager service.

Types need to be registered in order to be used in the platform.  Types are automatically registered when they are used in a flow or rule step or as part of a hosted service definition.  If you want to register a type without using it, you should call the register native type method.

 TypeUtilities.RegisterNativeType(theType);

Note: only types, not array versions of types, are to be registered.

After Service Host Manager has finished restarting, log into the Decisions portal. Within any list of datatypes you will see the types you just added. As an example, you can create a new flow and use the Create Data step to view available types to select from. Within the type picker menugo to System > Designers > DataStructures. You should see the Class Library that you created in Visual Studio. Below is a sample screen shot showing how this list would look after publishing the type shown in the example code above.

SelectClassLibrary-1.png

Was this article helpful?