Forum Discussion

DanTheMan's avatar
DanTheMan
New Contributor
2 days ago

Unable to set the CreditAmount in JournalLineItem for journals created with Business Rule

I can't seem to figure out why the CreditAmount  in the JournalLineItem  isn't reflecting the number that I assign to it. It's always zero no matter what. Is anyone experiencing this issue? see my code below.

Sub CreateJournal(ByVal si As SessionInfo)

Try

'Set up a new journal header.

Dim journalObjectHeader As New JournalHeader()

With journalObjectHeader

.Name = "Test_Journal"

.Description = "This is a test journal"

.WorkflowProfileID = si.WorkflowClusterPk.ProfileKey

.MemberIds.Scenario = si.WorkflowClusterPk.ScenarioKey

.MemberIds.Time = si.WorkflowClusterPk.TimeKey

.JournalStatus = JournalStatus.Working

.IsSingleEntity = False

End With

 

Dim journalObjectLineItems As New List(Of JournalLineItem)

 

'Create the first journal line item

Dim jnLineItem1 As New JournalLineItem

With jnLineItem1

.EntityId = BRApi.Finance.Members.GetMemberId(si, DimType.Entity.Id, "100_US")

.AccountId = BRApi.Finance.Members.GetMemberId(si, DimType.Account.Id, "10220030")

.FlowId = BRApi.Finance.Members.GetMemberId(si,DimType.Flow.Id, "EndBal")

.ICId= BRApi.Finance.Members.GetMemberId(si, DimType.IC.Id, "None")

.DebitAmount.Amount = 150

End With 

journalObjectLineItems.Add(jnLineItem1)

 

 

'Create the 2nd journal line item

Dim jnLineItem2 As New JournalLineItem

With jnLineItem2

.EntityId = BRApi.Finance.Members.GetMemberId(si, DimType.Entity.Id, "100_US")

.AccountId = BRApi.Finance.Members.GetMemberId(si, DimType.Account.Id, "10220050")

.FlowId = BRApi.Finance.Members.GetMemberId(si,DimType.Flow.Id, "EndBal")

.ICId= BRApi.Finance.Members.GetMemberId(si, DimType.IC.Id, "None")

.CreditAmount.Amount = - 150

End With 

journalObjectLineItems.Add(jnLineItem2)

 

 

'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

1 Reply

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    It might be better to use DecimalAndNoData objects to assign JournalLineItem.DebitAmount and JournalLineItem.CreditAmount.  I don't think you can directly assign a decimal value to these.

                .DebitAmount = New DecimalAndNoData(0.0D, True),
                .CreditAmount = New DecimalAndNoData(-150, False)

    Putting it all together:

    Sub CreateJournal(ByVal sessionInfo As SessionInfo)
        Try
            ' member IDs
            Dim entityId As Integer = BRApi.Finance.Members.GetMemberId(sessionInfo, DimType.Entity.Id, "100_US")
            Dim debitAccountId As Integer = BRApi.Finance.Members.GetMemberId(sessionInfo, DimType.Account.Id, "10220030")
            Dim creditAccountId As Integer = BRApi.Finance.Members.GetMemberId(sessionInfo, DimType.Account.Id, "10220050")
            Dim flowId As Integer = BRApi.Finance.Members.GetMemberId(sessionInfo, DimType.Flow.Id, "EndBal")
            Dim intercompanyId As Integer = BRApi.Finance.Members.GetMemberId(sessionInfo, DimType.IC.Id, "None")
    
            '  journal header
            Dim journalHeader As New JournalHeader() With {
                .Name = "Test_Journal",
                .Description = "This is a test journal",
                .WorkflowProfileID = sessionInfo.WorkflowClusterPk.ProfileKey,
                .JournalStatus = JournalStatus.Working,
                .IsSingleEntity = False,
                .MemberIds = New KeyedByDimTypeList(Of Integer)() With {
                    .Scenario = sessionInfo.WorkflowClusterPk.ScenarioKey,
                    .Time = sessionInfo.WorkflowClusterPk.TimeKey
                }
            }
    
            ' line items
            Dim debitLineItem As New JournalLineItem() With {
                .EntityId = entityId,
                .AccountId = debitAccountId,
                .FlowId = flowId,
                .ICId = intercompanyId,
                .DebitAmount = New DecimalAndNoData(150, False),
                .CreditAmount = New DecimalAndNoData(0.0D, True)
            }
    
            Dim creditLineItem As New JournalLineItem() With {
                .EntityId = entityId,
                .AccountId = creditAccountId,
                .FlowId = flowId,
                .ICId = intercompanyId,
                .DebitAmount = New DecimalAndNoData(0.0D, True),
                .CreditAmount = New DecimalAndNoData(-150, False)
            }
    
            ' line items list
            Dim journalLineItems As New List(Of JournalLineItem) From {
                debitLineItem,
                creditLineItem
            }
    
            ' Create and save the journal
            Dim journal As New Journal(journalHeader, journalLineItems)
            BRApi.Journals.Metadata.SaveJournalOrTemplateUsingIds(sessionInfo, journal, False, True)
    
        Catch ex As Exception
            Throw ErrorHandler.LogWrite(sessionInfo, New XFException(sessionInfo, ex))
        End Try
    End Sub

    Curious why you are making the credit amount negative?...