SDK: Consuming Data (Advanced)
  • 07 Aug 2024
  • 1 Minute to read
  • Dark
    Light

SDK: Consuming Data (Advanced)

  • Dark
    Light

Article summary

Version 7.x .NET Architecture Change

Overview

When writing an advanced step, the class must inherit from IDataConsumer for the step to have input data that can be mapped in at runtime.
The below line of code illustrates a class that inherits from IDataConsumer.

public class SampleFlowStepInputs: BaseFlowAwareStep, ISyncStep, IDataConsumer
Decisions has a Public GitHub Repository with various SDK examples available.

Example

After inheriting from IDataConsumer, the interface will need to be implemented. The implementation of this interface returns an array of DataDescription[]. The below sample code illustrates two inputs: single text input and an array text input.

The names of these inputs are set to a constant string variable. This is not necessary but is a best practice since this value refers to the input data in the run method of the created step.


 public DataDescription[] InputData
{
    get
    {
        return new DataDescription[] 
        {
            new DataDescription(new DecisionsNativeType(typeof(string)), INPUT_TEXT),
            new DataDescription(new DecisionsNativeType(typeof(string)), INPUT_TEXT_ARRAY, true, false, false)
        };
    }
}

Consuming Data for Flow step

The input value of a Flow step will be consumed in the run method. The input data values will be contained in a dictionary within the run method. This dictionary is data.Data. Use the name of the input data as the key to refer to it in the dictionary as shown below. In code example below, the variables valueOfTextInput and valueOfTextArrayInput[] have been populated with the respective input data.

  public ResultData Run(StepStartData data)
{
    string valueOfTextInput = (string)data.Data[INPUT_TEXT];
    string[] valueOfTextArrayInput = (string[])data.Data[INPUT_TEXT_ARRAY];
    return new ResultData("Done");
}


Consuming Data for a Rule step

Consuming data for a Rule step is much the same as a Flow step with one exception. The anchor data of the Rule step is automatically available inside the run method of the Rule step. Therefore, it does not need to be handed in separately. This anchor data is available in the data.Data dictionary with the key to this.AnchorData.Name.

The code below shows an example of a Rule's run method that compares the anchor data to an additional input added to the Rule.

 public override bool Run(RuleStepExecutionData data)
{
    string input = (string)data.Data[this.AnchorData.Name];
    string textToEval = (string)data.Data[INPUT_TEXT_TO_EVALUATE];
   return input.Equals(textToEval, StringComparison.OrdinalIgnoreCase);
}



Was this article helpful?