11-19-2021 09:55 AM - last edited on 01-12-2023 10:06 AM by JackLacava
11-19-2021 09:56 AM - edited 09-05-2023 05:50 AM
Yes, it is possible, here is a sample:
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_2022M3"
Dim oldJournalObject As JournalEx = BRApi.Journals.Metadata.GetJournalOrTemplate(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))
'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
'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)
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Sub
12-01-2021 06:01 AM
This is very useful especially when you want recurring adjustments. However one word of warning to anyone using automated rules top copy journals: Be very careful you don't accidentally use such tools to roll-forward AutoReversing journals, because then you end up with the auto-reversals being posted in all future periods, in a way that is stuck in the database and you cannot remove them easily. So anyone who wants to implement such a BR , I would recommend the following checks: Check that the JournalType ( in the JournalSummaryInfo ) is not one of JournalType.AutoReversal, or JournalType.AutoReversing
11-19-2021 09:56 AM - edited 09-05-2023 05:50 AM
Yes, it is possible, here is a sample:
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_2022M3"
Dim oldJournalObject As JournalEx = BRApi.Journals.Metadata.GetJournalOrTemplate(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))
'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
'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)
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Sub
09-05-2023 05:58 AM
People asked me, how to get a list of journals for a specific workflow/time/scenario. Here it is:
Dim wfClusterPk As New WorkflowUnitClusterPk()
wfclusterpk.ProfileKey = MyProfileKey
wfclusterpk.ScenarioKey = MyScenarioKey
wfclusterpk.TimeKey = MyTimeKey
Dim journalsCollection As JournalsAndTemplatesForWorkflow = BRApi.Journals.Metadata.GetJournalsAndTemplates(si,wfClusterPK)
For Each oJournal As Journalsummaryinfo In journalsCollection.Journals
…
Next
or for the actual workflow selection:
Dim wfClusterPk As WorkflowUnitClusterPk = si.WorkflowClusterPk
Dim journalsCollection As JournalsAndTemplatesForWorkflow = BRApi.Journals.Metadata.GetJournalsAndTemplates(si,wfClusterPK)
For Each oJournal As Journalsummaryinfo In journalsCollection.Journals
…
Next
03-20-2024 06:58 PM
Thanks this is great. Why line 16 is required if the strOldName is already getting only the Journal Name in Line 14.
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))
journalObjectHeader.Name = $"RF_{strOldName}{strPostfix}"
03-31-2024 07:14 AM
I use it to remove workflow-scenario-time information from the real name.
12-01-2021 06:01 AM
This is very useful especially when you want recurring adjustments. However one word of warning to anyone using automated rules top copy journals: Be very careful you don't accidentally use such tools to roll-forward AutoReversing journals, because then you end up with the auto-reversals being posted in all future periods, in a way that is stuck in the database and you cannot remove them easily. So anyone who wants to implement such a BR , I would recommend the following checks: Check that the JournalType ( in the JournalSummaryInfo ) is not one of JournalType.AutoReversal, or JournalType.AutoReversing