Ando
9 days agoNew Contributor II
Recurring journal with Auto Post
So im trying to create a rule that pulls selected journals forward than posts them automaticaly. I have my test journal pulling forward as expected but when im trying to post the journal in rule below its causing the rule to error. The line in question is,
BRApi.Journals.Process.ExecutePost(si, journalObjectHeader.UniqueID)
What am i missing it seems pretty straight forward?
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
Imports System.IO.Compression
Namespace OneStream.BusinessRule.Extender.CA_JournalRecurring2
Public Class MainClass
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.Unknown
CopyJournal(si)
Case Is = ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep
Case Is = ExtenderFunctionType.ExecuteExternalDimensionSource
'Add External Members
Dim externalMembers As New List(Of NameValuePair)
externalMembers.Add(New NameValuePair("YourMember1Name","YourMember1Value"))
externalMembers.Add(New NameValuePair("YourMember2Name","YourMember2Value"))
Return externalMembers
End Select
Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function
Private Sub CopyJournal(ByVal si As SessionInfo)
Try
'retrieve the names of the workflow parameters and concatenate them together
Dim profilePostfix As String = brapi.Workflow.Metadata.GetProfile(si,si.WorkflowClusterPk.ProfileKey).Name
Dim scenarioPostfix As String = brapi.Finance.Members.GetMemberName(si,dimtype.Scenario.Id, si.WorkflowClusterPk.ScenarioKey)
Dim timePostfix As String = brapi.Finance.Members.GetMemberName(si, dimtype.Time.Id, si.WorkflowClusterPk.TimeKey)
Dim strPostfix As String = $"{profilePostfix}_{scenarioPostfix}_{timePostfix}"
'The name of the journal to copy
Dim journalName As String ="Tax Accruals_Houston.journals_Actual_2011M2"
Dim oldJournalObject As JournalEx = BRApi.Journals.Metadata.GetJournalOrTemplate(si, journalName)
brapi.ErrorLog.LogMessage(si, journalName)
'Remove the postfix from the old journal name to get the name
Dim strOldName As String = oldJournalObject.Header.Header.Name
Dim oldProfileName As String = brapi.Workflow.Metadata.GetProfile(si,oldJournalObject.Header.Header.WorkflowProfileID).Name
strOldName = strOldName.Remove(strOldName.IndexOf(oldProfileName))
brapi.ErrorLog.LogMessage(si, strOldName)
'create a copy of the journal header
Dim journalObjectHeader As New JournalHeader(oldJournalObject.Header.Header)
'Update the required parameters
journalObjectHeader.Name = $"RF_{strOldName}{strPostfix}"
journalObjectHeader.Description = $"Roll Forward from {oldJournalObject.Header.Header.name}: {oldJournalObject.Header.Header.Description}"
journalObjectHeader.UniqueID = Guid.NewGuid()
journalObjectHeader.MemberIds.Scenario = si.WorkflowClusterPk.ScenarioKey
journalObjectHeader.MemberIds.Time = si.WorkflowClusterPk.TimeKey
journalObjectHeader.WorkflowProfileID = si.WorkflowClusterPk.ProfileKey
' Log the unique ID Of the journal before posting
brapi.ErrorLog.LogMessage(si, $"Journal UniqueID: {journalObjectHeader.UniqueID}")
'Journal status as working
journalObjectHeader.JournalStatus = JournalStatus.Working
'Create a copy of the journal line item using linq
Dim journalObjectLineItems As list(Of JournalLineItem) = oldJournalObject.LineItems.Select(Function(x) New JournalLineItem(x.LineItem)).tolist
'Create a new journal object
Dim journalObject As New Journal(journalObjectHeader, journalObjectLineItems)
'Save it
BRApi.Journals.Metadata.SaveJournalOrTemplateUsingIds(si, journalObject, False, True)
' Post the journal using ExecutePost
BRApi.Journals.Process.ExecutePost(si, journalObjectHeader.UniqueID)
brapi.ErrorLog.LogMessage(si, $"Journal '{journalObjectHeader.Name}' posted successfully.")
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Sub