Finance Rules

The Finance Rules API

This guide covers the key API objects available inside Finance Business Rules — the context-specific api object, the application-wide BRApi static class, and mechanisms for sharing code between rules.

The Finance Rules API Object

The api parameter passed to Finance Business Rules (FinanceRulesApi) exposes a rich set of properties for interacting with the current execution context:
PropertyTypeDescription
api.FunctionTypeFinanceFunctionTypeThe operation that triggered the rule
api.EntityEntityApiCurrent entity being processed
api.ScenarioScenarioApiCurrent scenario
api.TimeTimeApiCurrent time period
api.ViewViewApiCurrent view (Periodic, YTD, etc.)
api.AccountAccountApiCurrent account context
api.FlowFlowApiCurrent flow member
api.ConsConsApiConsolidation context
api.DataDataApiRead/write cube data
api.MembersMembersApiAccess dimension members
api.DimensionsDimensionsApiAccess dimension metadata
api.CubesCubesApiAccess cube definitions
api.PovPovApiFull Point of View context
api.WorkflowWorkflowApiWorkflow context
api.FunctionsFunctionsApiUtility and helper functions
api.FxRatesFxRatesApiForeign exchange rate access
api.CalcStatusCalcStatusApiCalculation status tracking
api.ProfilerFinanceProfilerApiPerformance profiling
api.UD1api.UD8UDApiUser-defined dimension members
1' Common api usage patterns
2Dim currentEntity As String = api.Entity.Name
3Dim currentScenario As String = api.Scenario.Name
4Dim currentTime As String = api.Time.Name
5
6' Check if processing a base entity vs. parent
7If api.Entity.IsBase Then
8  ' Logic for base entities only
9End If
10
11' Access user-defined dimensions
12Dim ud1Member As String = api.UD1.Name

The BRApi Static Class

While the api object is context-specific to each rule execution, BRApi is a static class available across all rule types. It provides application-wide services:
PropertyDescription
BRApi.FinanceFinance engine access — data, dimensions, members, metadata, calculations
BRApi.ErrorLogWrite messages and errors to the application error log
BRApi.DatabaseDirect database access
BRApi.SecurityUser and role information
BRApi.WorkflowWorkflow operations
BRApi.StateApplication state and shared variables between rules
BRApi.UtilitiesGeneral utilities (file harvest, batch processing, etc.)
BRApi.FileSystemFile system operations
BRApi.ImportData import operations
BRApi.FormsForms API access
BRApi.JournalsJournal entry operations
BRApi.DashboardsDashboard operations
BRApi.CubeViewsCubeView operations
BRApi.DataQualityData quality and validation
BRApi.TaskActivityTask and activity tracking
BRApi.ProfilerPerformance profiling and diagnostics
BRApi.MetricsMetrics and monitoring

BRGlobals

The globals parameter is passed to every Business Rule's Main function. It provides a way to store and retrieve objects that persist in memory throughout a single calculation or consolidation process.
This is useful when you need to perform an expensive operation (such as a SQL query or loading a large reference dataset) once and reuse the result across multiple Data Unit executions:
1' Check if we already cached the lookup table
2Dim lookupTable As DataTable = Nothing
3If globals.ContainsKey("MyLookupTable") Then
4  lookupTable = DirectCast(globals("MyLookupTable"), DataTable)
5Else
6  ' First Data Unit — run the query and cache the result
7  lookupTable = BRApi.Database.ExecuteSql(si, "SELECT EntityName, Rate FROM dbo.CustomRates", False)
8  globals("MyLookupTable") = lookupTable
9End If
10
11' Use lookupTable for the current Data Unit's calculation...
⚠️Warning
Objects stored in globals remain in memory for the entire calculation process. Avoid caching very large datasets or objects that hold open connections — this can cause memory pressure on the application server. Only cache what you truly need to reuse.

Sharing Code Across Rules

As your application grows, you'll want to avoid duplicating logic across multiple Business Rules. OneStream provides two mechanisms for code reuse.

ContainsGlobalFunctionsForFormulas

Every Business Rule has a ContainsGlobalFunctionsForFormulas property. When set to True, any Public Function defined in that rule becomes available to Member Formulas and other rules throughout the application.
This is the simplest way to create shared utility functions — write them in a dedicated Business Rule, enable the property, and call them from anywhere.

BR Referencing

For more structured code sharing, you can reference one Business Rule from another using the Referenced Assemblies property. Add a reference using the BR\ prefix followed by the rule name:
Referenced Assembly: BR\SharedFinanceFunctions
Then instantiate and call the referenced rule's class:
1' Instantiate the shared rule's class
2Dim sharedBR As New OneStream.BusinessRule.Finance.SharedFinanceFunctions.MainClass
3
4' Call a function from the shared rule
5Dim result As String = sharedBR.MySharedFunction(si, globals, api, args)
💡Tip
Use ContainsGlobalFunctionsForFormulas for simple utility functions that Member Formulas need access to. Use BR referencing when you have a dedicated shared library with multiple functions that other Business Rules (not just Member Formulas) need to call.
ℹ️Info
For a more robust code-sharing approach, consider using Workspace Assemblies. Assemblies compile multiple files into a single unit with proper class-level dependencies. See Getting Started with Workspace Assemblies.