Forum Discussion
Hi Abrandm,
Take a look at the BR below for extract of an Entity dimension.
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_ExportAppTypes
Public Class MainClass
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Reference Code: XFR_ExportAppTypes
'
'Description: Executes application extracts and produces XML file.
' This can be run for different extract types like Metadata or CubeViews
' The file is 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.
'
'Created By: Peter Fu
'
'Date Created: 06-05-2021
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object
Try
Select Case args.FunctionType
Case Is = ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep
'Get Configuration Settings
Dim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si)
'Data Management extract location
Dim folderPath As String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder,
si.AppToken.AppName
) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\Extracts" 'If the directory does not exist create
If Not Directory.Exists(folderPath) Then Directory.CreateDirectory(folderPath)
'Full path and file name for extract
Dim filePath As String = folderPath & "\MetadataEntity " & DateTime.UtcNow.ToString("yyyyMMdd") & ".xml"
'If file already exist
If File.Exists(filePath) Then File.Delete(filePath)
'Extract Options
Dim xmlOptions As New XmlExtractOptions
xmlOptions.ExtractAllItems = False
'Extract dimensions
Dim extractDict As New Dictionary(Of XmlExtractItemPk, Boolean)
extractDict.Add(New XmlExtractItemPk(XmlExtractItemType.Dimensions), True)
'Extract Houston Entities
Dim dimID As Integer = BRApi.Finance.Dim.GetDimPk(si, "HoustonEntities").DimId
extractDict.Add(New XmlExtractItemPk(XmlExtractItemType.Dimension, dimID), True)
'Execute the Metadata Extract
Using dbConnFW As DbConnInfo = BRApi.Database.CreateFrameworkDbConnInfo(si)
Using dbConnApp As DbConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
'Extract XML metadata to target location
File.WriteAllText(filePath, MetadataExtract.ExtractXml(dbConnFW, dbConnApp, xmlOptions, extractDict))
End Using
End Using
End Select
Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function
End Class
End Namespace
Regards,
Peter
Thank you Peter, this is very helpful! I was able to stack multiple dimensions into one metadata extract with this.
To take it one step further, do you know if there is a way to extract just the members out of a dimension or just the relationships? I would think that this could be done by adding this to the extractDict. I do not see anything related to this under the XmlExtractItemType though.
Thanks,
Adam
- PeterFu2 years agoContributor II
Hi Adam,
Take a look at the BR below.
Imports SystemImports System.DataImports System.Data.CommonImports System.IOImports System.Collections.GenericImports System.GlobalizationImports System.LinqImports Microsoft.VisualBasicImports System.Windows.FormsImports OneStream.Shared.CommonImports OneStream.Shared.WcfImports OneStream.Shared.EngineImports OneStream.Shared.DatabaseImports OneStream.Stage.EngineImports OneStream.Stage.DatabaseImports OneStream.Finance.EngineImports OneStream.Finance.DatabaseNamespace OneStream.BusinessRule.Extender.XFR_ExportAppTypesPublic Class MainClass'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'Reference Code: XFR_ExportAppTypes''Description: Executes application extracts and produces XML file.' This can be run for different extract types like Metadata or CubeViews' The file is 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.''Created By: Peter Fu''Date Created: 06-05-2021'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As ObjectTrySelect Case args.FunctionTypeCase Is = ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep'Get Configuration SettingsDim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si)'Data Management extract locationDim folderPath As String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, _si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\Extracts"'If the directory does not exist createIf Not Directory.Exists(folderPath) Then Directory.CreateDirectory(folderPath)'Full path and file name for extractDim filePath As String = folderPath & "\MetadataEntity " & DateTime.UtcNow.ToString("yyyyMMdd") & ".xml"'If file already existIf File.Exists(filePath) Then File.Delete(filePath)'-------------------------------------------------------------------------------------------------------------------------'Extract OptionsDim xmlOptions As New XmlExtractOptionsxmlOptions.ExtractAllItems = False'Extract dimensionsDim extractDict As New Dictionary(Of XmlExtractItemPk, Boolean)extractDict.Add(New XmlExtractItemPk(XmlExtractItemType.Dimensions), True)'Extract EntitiesDim dimID As Integer = BRApi.Finance.Dim.GetDimPk(si, "CorpEntities").DimIdextractDict.Add(New XmlExtractItemPk(XmlExtractItemType.Dimension, dimID), True)'Define dimension options for extractDim xmlDimOptions As New XmlExtractMetadataDimOptions'Extract specified membersxmlDimOptions.ExtractAllMembers = False'Member(s) to extractDim memExtract As New Dictionary(Of String, Object)memExtract.Add("All Orgs", Nothing)'memExtract.Add("Corporate", Nothing)xmlDimOptions.MembersToExtract = memExtract'Extract all member relationshipsxmlDimOptions.ExtractAllRelationships = False'Extract members for each relationshipxmlDimOptions.ExtractMembersForEachSelectedRelationship = False'Define Metadata extract options'Dim EntID As New Dictionary(Of DimPk, XmlExtractMetadataDimOptions)'EntID = BRApi.Finance.Dim.GetDimPk(si, "Total Golfstream")Dim xmlMetadataOptions As New XmlExtractMetadataOptions()'Entity Dimension typeDim dimT As Integer = DimType.Entity.Id'Set the extract dimension options for specified dimensionxmlMetadataOptions.SetOptionsForDimension(dimT, dimID, xmlDimOptions)'Add dimension member options to metadata optionsxmlOptions.MetadataOptions = xmlMetadataOptions'Execute the Metadata ExtractUsing dbConnFW As DbConnInfo = BRApi.Database.CreateFrameworkDbConnInfo(si)Using dbConnApp As DbConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)'Extract XML metadata to target locationFile.WriteAllText(filePath, MetadataExtract.ExtractXml(dbConnFW, dbConnApp, xmlOptions, extractDict))End UsingEnd UsingEnd SelectReturn NothingCatch ex As ExceptionThrow ErrorHandler.LogWrite(si, New XFException(si, ex))End TryEnd FunctionEnd ClassEnd Namespace#End Region "Export Dimension Metadata to XML File"Regards,Peter- denisefockler2 years agoNew Contributor III
Peter, I know I am not the poster of the original question but I ran across your solution above as I am trying to automate the extract of simple parent/child relationships for a several of our dimensions. I tried your code above and I am getting the following error when compiling.
- AdamB2 years agoNew Contributor II
Hi Denise, I am having this same issue. Thanks for your reply
- jwagner5 months agoNew Contributor III
Where is this MetadataExtract.ExtractXML function coming from? I'm trying to expand on this idea except with all Object Types including dashboards, cube views etc. Is there something similar for them?
Related Content
- 4 months ago
- 2 years ago
- 11 months ago
- 11 months ago
- 10 months ago