Is there anyway to download TB/Reclass files automatically using Business Rules?
- 3 years ago
Hi Yashwant,
Here you have the code, I have copied in both XFR_ExportStageDat and XFR_ExportStageArchives
XFR_ExportStageData:
Imports System Imports System.Data Imports System.Data.Common Imports System.IO Imports System.Collections.Generic Imports System.Globalization Imports System.Linq Imports Microsoft.VisualBasic Imports System.Windows.Forms Imports OneStream.Shared.Common Imports OneStream.Shared.Wcf Imports OneStream.Shared.Engine Imports OneStream.Shared.Database Imports OneStream.Stage.Engine Imports OneStream.Stage.Database Imports OneStream.Finance.Engine Imports OneStream.Finance.Database Namespace OneStream.BusinessRule.Extender.XFR_ExportStageData Public Class MainClass '------------------------------------------------------------------------------------------------------------ 'Reference Code: XFR_ExportStageSourceData ' 'Description: Extender buiness rule that exports the stage source data to a single delimited files ' for all import child workflow pofiles. The files are written to the application ' Data Mgmt Export folder in the file share directory. ' 'Usage: Can be executed from Business Rule editor or run as part of a Data Management sequence. ' Note: If called from a Data Management sequence, the business rule step must supply 3 ' paramaters named as follows (WfProfileName, ScenarioName, TimeName) ' 'Created By: Tom Shea 'Date Created: 5-9-2013 '------------------------------------------------------------------------------------------------------------ 'Module level variables Private m_ColNamesWritten As Boolean = False Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object Try 'Define the workflow cluster used as the starting point to extract from Dim wfClusterPk As New WorkflowUnitClusterPk Dim wfProfileName As String = String.Empty Dim scenarioName As String = String.Empty Dim timeName As String = String.Empty Select Case args.FunctionType Case Is = ExtenderFunctionType.Unknown 'Set the parent workflow unit to extract input profiles for wfProfileName = "Houston" scenarioName = "Actual" timeName = "2011M2" wfClusterPk = BRAPi.Workflow.General.GetWorkflowUnitClusterPk(si, wfProfileName, scenarioName, timeName) Case Is = ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep 'Since this is being called from a DataManagement job, get the wfCluster from the parameters defined in the DataMgmt sequence wfProfileName = args.NameValuePairs("WfProfileName") scenarioName = args.NameValuePairs("ScenarioName") timeName = args.NameValuePairs("TimeName") wfClusterPk = BRAPi.Workflow.General.GetWorkflowUnitClusterPk(si, wfProfileName, scenarioName, timeName) End Select 'Prepare the Stage Data Extract File path Dim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si) Dim folderPath As String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\StageData" If Not Directory.Exists(folderPath) Then Directory.CreateDirectory(folderPath) Dim filePath As String = folderPath & "\DataExtract_" & scenarioName & "_" & timeName & ".csv" If File.Exists(filePath) Then File.Delete(filePath) 'Export data for each descendant workflow profile Dim profileInfos As List(Of WorkflowProfileInfo) = BRAPi.Workflow.Metadata.GetRelatives(si, wfClusterPk, WorkflowProfileRelativeTypes.Descendants, WorkflowProfileTypes.InputImportChild) If Not profileInfos Is Nothing Then 'Create the list of columns to export Dim colList As New List(Of String) colList.Add("WFProfileName") colList.Add("EtT") colList.Add("AcT") colList.Add("RawAmount") Dim isFirstFile As Boolean = True For Each profileInfo As WorkflowProfileInfo In profileInfos Dim wfClusterPkChild As New WorkflowUnitClusterPk(profileInfo.ProfileKey, wfClusterPk.ScenarioKey, wfClusterPk.TimeKey) If isFirstFile Then isFirstFile = False BRAPi.Import.Data.ExportStageData(si, wfClusterPkChild, Nothing, Nothing, True, filePath, False, ".", True) Else BRAPi.Import.Data.ExportStageData(si, wfClusterPkChild, Nothing, Nothing, False, filePath, True, ".", True) End If Next End If Return Nothing Catch ex As Exception Throw ErrorHandler.LogWrite(si, New XFException(si, ex)) End Try End Function End Class End Namespace
XFR_ExportStageArchives:
Imports System Imports System.Data Imports System.Data.Common Imports System.IO Imports System.Collections.Generic Imports System.Globalization Imports System.Linq Imports Microsoft.VisualBasic Imports System.Windows.Forms Imports OneStream.Shared.Common Imports OneStream.Shared.Wcf Imports OneStream.Shared.Engine Imports OneStream.Shared.Database Imports OneStream.Stage.Engine Imports OneStream.Stage.Database Imports OneStream.Finance.Engine Imports OneStream.Finance.Database Namespace OneStream.BusinessRule.Extender.XFR_ExportStageArchives Public Class MainClass '------------------------------------------------------------------------------------------------------------ 'Reference Code: XFR_ExportStageArchives ' 'Description: Extender buiness rule that exports the stage archive files for all import child workflow ' profiles of the specified parent workflow profile. The files are written to the application ' Data Mgmt Export folder in the file share directory. ' 'Usage: Can be executed from Business Rule editor or run as part of a Data Management sequence. ' Note: If called from a Data Management sequence, the business rule step must supply 3 ' paramaters named as follows (WfProfileName, ScenarioName, TimeName) ' 'Created By: Tom Shea 'Date Created: 5-9-2013 '------------------------------------------------------------------------------------------------------------ Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object Try 'Define the workflow cluster used as the starting point to extract from Dim wfClusterPk As New WorkflowUnitClusterPk Dim wfProfileName As String = String.Empty Dim scenarioName As String = String.Empty Dim timeName As String = String.Empty Select Case args.FunctionType Case Is = ExtenderFunctionType.Unknown 'Set the parent workflow unit to extract input profiles for wfProfileName = "Houston" scenarioName = "Actual" timeName = "2011M2" wfClusterPk = BRAPi.Workflow.General.GetWorkflowUnitClusterPk(si, wfProfileName, scenarioName, timeName) Case Is = ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep 'Since this is being called from a DataManagement job, get the wfCluster from the parameters defined in the DataMgmt sequence wfProfileName = args.NameValuePairs("WfProfileName") scenarioName = args.NameValuePairs("ScenarioName") timeName = args.NameValuePairs("TimeName") wfClusterPk = BRAPi.Workflow.General.GetWorkflowUnitClusterPk(si, wfProfileName, scenarioName, timeName) End Select 'Prepare the Stage Data Extract File path Dim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si) Dim folderPath As String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\StageArchives\" & scenarioName & "\" & timeName If Not Directory.Exists(folderPath) Then Directory.CreateDirectory(folderPath) 'Export data for each descendant workflow profile Dim profileInfos As List(Of WorkflowProfileInfo) = BRAPi.Workflow.Metadata.GetRelatives(si, wfClusterPk, WorkflowProfileRelativeTypes.Descendants, WorkflowProfileTypes.InputImportChild) If Not profileInfos Is Nothing Then For Each profileInfo As WorkflowProfileInfo In profileInfos Dim wfClusterPkChild As New WorkflowUnitClusterPk(profileInfo.ProfileKey, wfClusterPk.ScenarioKey, wfClusterPk.TimeKey) BRAPi.Import.Data.ExportStageArchives(si, wfClusterPkChild, folderPath, False) Next End If Return Nothing Catch ex As Exception Throw ErrorHandler.LogWrite(si, New XFException(si, ex)) End Try End Function End Class End Namespace
You can get the Golfstream application from the MarketPlace as well.
Regards,
Peter
- 3 years ago
If you're looking to download the original TB file as imported into a workflow-scenario-period, use ExportStageArchives function. Below is an example within an extender rule. The file is stored under File Share \ Data Management folder. You can specify a more convenient folder by updating the folderPath variable.
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object
Try
Dim profileName As String = "Houston"
Dim scenarioName As String = "Actual"
Dim timeName As String = "2022M3"
Dim wfClusterPk As WorkflowUnitClusterPk = BRApi.Workflow.General.GetWorkflowUnitClusterPk(si, profileName, scenarioName, timeName)
Dim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si)
Dim folderPath As String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, _
si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\StageArchives\" & scenarioName & "\" & timeName
If Not Directory.Exists(folderPath) Then Directory.CreateDirectory(folderPath)
brapi.Import.Data.ExportStageArchives(si, wfClusterPk, folderPath,False)Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function