Forum Discussion
- Nikpowar97Contributor
I wrote a code from my end for my Account dimensions (you can replicate for others)
Imports System Imports System.Collections.Generic Imports System.Data Imports System.Data.Common Imports System.Globalization Imports System.IO Imports System.Linq Imports Microsoft.VisualBasic Imports OneStream.Finance.Database Imports OneStream.Finance.Engine Imports OneStream.Shared.Common Imports OneStream.Shared.Database Imports OneStream.Shared.Engine Imports OneStream.Shared.Wcf Imports OneStream.Stage.Database Imports OneStream.Stage.Engine Namespace OneStream.BusinessRule.DashboardDataSet.AccountHierarchyTable Public Class MainClass Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DashboardDataSetArgs) As Object Try Select Case args.FunctionType Case Is = DashboardDataSetFunctionType.GetDataSet If args.DataSetName.XFEqualsIgnoreCase("GetAccountStructure") Then Dim Acct As String = args.NameValuePairs.XFGetValue("Acct") 'Get Top Parent Dim Sql As String = "SELECT Member.Name As L1,Member.Description As Description_L1 FROM Relationship RIGHT OUTER JOIN Member ON Relationship.DimTypeId = Member.DimTypeId AND Relationship.ChildID = Member.MemberId WHERE (Member.DimTypeId = 5) AND Member.DimId IN (SELECT DimId FROM Dim WHERE Name = 'DIMNAME_Accounts') AND (Relationship.ParentId = '-2') and Member.Name = '"& Acct &"' ORDER BY Member.Name" Dim Dt As New DataTable Using AppCon As DbConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si) dt = BRApi.Database.ExecuteSql(AppCon,Sql,True) End Using Dim i As Integer = 1 Dim conditionMet As Boolean = False Dim DataTable As New DataTable DataTable.Columns.Add("L1") DataTable.Columns.Add("Description_L1") Dim DelRows As New List(Of DataRow)() 'NIK While Not conditionMet Dim rowsToAdd As New List(Of DataRow)() For Each Dr As DataRow In Dt.Rows Dim ColName As String = "L" & i.ToString If dr(ColName).ToString = String.Empty Then Continue For End If Dim ChildList As List(Of Member) = Brapi.Finance.Members.GetChildren(si,Brapi.Finance.Dim.GetDimPk(si,"DIMNAME_Accounts"),Brapi.Finance.Members.GetMemberId(si,Dimtypeid.Account,dr(ColName).ToString)) If ChildList.Count > 0 Then For Each Child As Member In ChildList Dim DataTBRow As DataRow = DataTable.newRow For Z As Integer = 1 To i DataTBRow("L" & Z.ToString) = Dr("L" & Z.ToString) DataTBRow("Description_L" & Z.ToString) = Dr("Description_L" & Z.ToString) Next If Not dataTable.Columns.Contains("L" & (i+1).ToString) Then DataTable.Columns.Add("L" & (i+1).ToString) DataTable.Columns.Add("Description_L" & (i+1).ToString) End If DataTBRow("L" & (i+1).ToString) = Child.Name DataTBRow("Description_L" & (i+1).ToString) = Child.Description If BRApi.Finance.Members.HasChildren(si,Brapi.Finance.Dim.GetDimPk(si,"DIMNAME_Accounts"),Brapi.Finance.Members.GetMemberId(si,Dimtypeid.Account,Child.Name)) Then 'NIK DelRows.Add(DataTBRow) End If rowsToAdd.Add(DataTBRow) conditionMet = False Next Else Continue For End If Next If Not dataTable.Columns.Contains( "L" & (i+1).ToString) Then conditionMet = True End If i = i + 1 For Each row In rowsToAdd DataTable.Rows.Add(row) Next dt = DataTable End While ' Next Dim LNum As Integer = 0 For Each Dc As DataColumn In Dt.Columns If Dc.ColumnName.Contains("L") And Not Dc.ColumnName.Contains("Description_L")Then If CInt(StringHelper.ReplaceString(Dc.ColumnName,"L","",True)) > 0 Then LNum = CInt(StringHelper.ReplaceString(Dc.ColumnName,"L","",True)) End If End If Next For Each rowToRemove In DelRows Dt.Rows.Remove(rowToRemove) Next For Each Dr1 As DataRow In Dt.Rows For L As Integer = LNum To 1 Step -1 Dim ClmnName As String = "L" & L If L = LNum And Not (Dr1.IsNull(ClmnName) OrElse Dr1(ClmnName).ToString() = String.Empty) Then Exit For Else If Dr1.IsNull(ClmnName) OrElse Dr1(ClmnName).ToString() = String.Empty Then Continue For Else Dr1("L" & LNum) = Dr1(ClmnName).ToString() Dr1("Description_L" & LNum) = Dr1("Description_" & ClmnName).ToString() Dr1(ClmnName) = String.Empty Dr1("Description_" & ClmnName) = String.Empty Exit For End If Next Next Dt.Columns("L" & LNum).ColumnName = "Base Account" Dt.Columns("Description_L" & LNum).ColumnName = "Base Account Description" Return Dt End If End Select Return Nothing Catch ex As Exception Throw ErrorHandler.LogWrite(si, New XFException(si, ex)) End Try End Function End Class End Namespace
- ELNew Contributor
Nikpowar97 - I'm trying to replicate this for Entity dimension and not getting the result table. Any insight would be appreciated, if you could share.
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DashboardDataSetArgs) As ObjectTrySelect Case args.FunctionTypeCase Is = DashboardDataSetFunctionType.GetDataSetNames'Dim names As New List(Of String)()'names.Add("MyDataSet")'Return names'Return GetDataSetNames("Getfunctionalhierarchy")'Case Is = DashboardDataSetFunctionType.GetDataSet'If args.DataSetName.XFEqualsIgnoreCase("MyDataSet") ThenCase Is = DashboardDataSetFunctionType.GetDataSetIf args.DataSetName.XFEqualsIgnoreCase("Getfunctionalhierarchy") ThenDim Center As String = args.NameValuePairs.XFGetValue("Functional_Reporting") 'Get Top ParentDim Sql As String = "SELECT Member.Name As L1, Member.Description As Description_L1FROM Relationship RIGHT OUTER JOIN Member ON Relationship.DimTypeId = Member.DimTypeId AND Relationship.ChildID = Member.MemberIdWHERE (Member.DimTypeId = 0) AND Member.DimId IN (SELECT DimId FROM Dim WHERE Name = 'OMFEntityCenter') AND (Relationship.parentid = '-2') and Member.Name = '"& Center &"'ORDER BY Member.Name"Dim Dt As New DataTableUsing AppCon As DbConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)dt = BRApi.Database.ExecuteSql(AppCon,Sql,True)End UsingDim i As Integer = 1Dim conditionMet As Boolean = FalseDim DataTable As New DataTableDataTable.Columns.Add("L1")DataTable.Columns.Add("Description_L1")Dim DelRows As New List(Of DataRow)() 'NIKWhile Not conditionMetDim rowsToAdd As New List(Of DataRow)()For Each Dr As DataRow In Dt.RowsDim ColName As String = "L" & i.ToStringIf dr(ColName).ToString = String.Empty ThenContinue ForEnd IfDim ChildList As List(Of Member) = Brapi.Finance.Members.GetChildren(si,Brapi.Finance.Dim.GetDimPk(si,"OMFEntityCenter"),Brapi.Finance.Members.GetMemberId(si,dimtypeid.Entity,dr(ColName).ToString))If ChildList.Count > 0 ThenFor Each Child As Member In ChildListDim DataTBRow As DataRow = DataTable.newRowFor Z As Integer = 1 To iDataTBRow("L" & Z.ToString) = Dr("L" & Z.ToString)DataTBRow("Description_L" & Z.ToString) = Dr("Description_L" & Z.ToString)NextIf Not dataTable.Columns.Contains("L" & (i+1).ToString) ThenDataTable.Columns.Add("L" & (i+1).ToString)DataTable.Columns.Add("Description_L" & (i+1).ToString)End IfDataTBRow("L" & (i+1).ToString) = Child.NameDataTBRow("Description_L" & (i+1).ToString) = Child.DescriptionIf BRApi.Finance.Members.HasChildren(si,Brapi.Finance.Dim.GetDimPk(si,"OMFEntityCenter"),Brapi.Finance.Members.GetMemberId(si,dimtypeid.Entity,Child.Name)) Then 'NIKDelRows.Add(DataTBRow)End IfrowsToAdd.Add(DataTBRow)conditionMet = FalseNextElseContinue ForEnd IfNextIf Not dataTable.Columns.Contains( "L" & (i+1).ToString) ThenconditionMet = TrueEnd Ifi = i + 1For Each row In rowsToAddDataTable.Rows.Add(row)Nextdt = DataTableEnd While' NextDim LNum As Integer = 0For Each Dc As DataColumn In Dt.ColumnsIf Dc.ColumnName.Contains("L") And Not Dc.ColumnName.Contains("Description_L")ThenIf CInt(StringHelper.ReplaceString(Dc.ColumnName,"L","",True)) > 0 ThenLNum = CInt(StringHelper.ReplaceString(Dc.ColumnName,"L","",True))End IfEnd IfNextFor Each rowToRemove In DelRowsDt.Rows.Remove(rowToRemove)NextFor Each Dr1 As DataRow In Dt.RowsFor L As Integer = LNum To 1 Step -1Dim ClmnName As String = "L" & LIf L = LNum And Not (Dr1.IsNull(ClmnName) OrElse Dr1(ClmnName).ToString() = String.Empty) ThenExit ForElse If Dr1.IsNull(ClmnName) OrElse Dr1(ClmnName).ToString() = String.Empty ThenContinue ForElseDr1("L" & LNum) = Dr1(ClmnName).ToString()Dr1("Description_L" & LNum) = Dr1("Description_" & ClmnName).ToString()Dr1(ClmnName) = String.EmptyDr1("Description_" & ClmnName) = String.EmptyExit ForEnd IfNextNextDt.Columns("L" & LNum).ColumnName = "Base Center"Dt.Columns("Description_L" & LNum).ColumnName = "Base Center Description"Return DtEnd IfEnd SelectReturn NothingCatch ex As ExceptionThrow ErrorHandler.LogWrite(si, New XFException(si, ex))End TryEnd Function
- CAIGuySeanFContributor
Any updates on this request?
- SxDNew Contributor III
Bump. Would also like to know if there has been a solution built for this export.
Related Content
- 6 months ago
- 2 years ago
- 3 years ago
- 2 years ago