Forum Discussion

DanTheMan's avatar
DanTheMan
New Contributor
11 days ago
Solved

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 co...
  • RobbSalzmann's avatar
    11 days ago

    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?...