Table of Contents

Data context

When executing a Calculation Flow, the Data Context specifies the context of which the Flow is run and determines the slice of data that is processed. When run from InVision, this is typically the filter selections made by the user. For example a specific department, an account group, or a selection of multiple different filters. The Data Context can also be constructed programatically by 3rd party clients or in a Function action.

Example - Data Context from InVision

To include a Data Context when running the Flow from InVision, please refer to this example.

Example - custom Data Context

This example shows how to programatically create a custom Data Context for a Calculation Flow. The code is defined in a Function action.

// Creating our own DataContext to simulate that the call comes from InVision.
return new Profitbase.Flow.Extensions.Invision.CalculationFlow.CalculationFlowDataContext
{
    ReferenceTableDataContexts = new List<Profitbase.Flow.Extensions.Invision.CalculationFlow.ReferenceTableDataContext>
    {
        new Profitbase.Flow.Extensions.Invision.CalculationFlow.ReferenceTableDataContext("Account", "AccountID", "3"),
        new Profitbase.Flow.Extensions.Invision.CalculationFlow.ReferenceTableDataContext("Account", "AccountID", "4"),
        new Profitbase.Flow.Extensions.Invision.CalculationFlow.ReferenceTableDataContext("Account", "AccountID", "5"),
        new Profitbase.Flow.Extensions.Invision.CalculationFlow.ReferenceTableDataContext("Account", "AccountID", "6"),
        new Profitbase.Flow.Extensions.Invision.CalculationFlow.ReferenceTableDataContext("Account", "AccountID", "7"),
        new Profitbase.Flow.Extensions.Invision.CalculationFlow.ReferenceTableDataContext("Account", "AccountID", "8"),
    },
    Arguments = new List<Profitbase.Flow.Extensions.Invision.CalculationFlow.DataContextArgument>
    {
        new Profitbase.Flow.Extensions.Invision.CalculationFlow.DataContextArgument("OutputName", "CalcTax")
    }
};

Example - Clone the Data Context passed in from InVision

When you run a Flow from an InVision Workbook with a DataContext, you sometimes need to make copies of the data context passed in to Flow, and replace certain values, for example which department you want to process data for. The easiest way to do this is to clone the data context passed in as the startup argument, and then modify the cloned object.

The example below shows how use a Function to easily create a new data context by cloning an existing one, and set which department id to use.

The list of dimensions has been loaded using the Get entitities action, using a query agains the SYS_Objects view in InVision.

public Profitbase.Flow.Extensions.Invision.CalculationFlow.CalculationFlowDataContext CreateScopedDataContext(Profitbase.Flow.Extensions.Invision.CalculationFlow.CalculationFlowDataContext globalDataContext, List<DimensionInfo> dimensions)
{   
    var departmentDimensionId = dimensions.FirstOrDefault(c => c.Name == "Department")?.ObjectID;    
    return globalDataContext
        .Clone()
        .SetReferenceTableDataContext(departmentDimensionId, "DepartmentID", "My-New-Department-Id");
}