Stored Procedures [dbo].[XLedgerMarkTransactionsPostAsFailure]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@batchIdint4
@exceptionnvarchar(max)max
@transactionsPostedbit1
@failureLocationvarchar(16)16
@batchItemIdsIntListmax
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
CREATE PROCEDURE [dbo].[XLedgerMarkTransactionsPostAsFailure]
    @batchId int,
    @exception nvarchar(max),
    @transactionsPosted bit,
    @failureLocation varchar(16),
    @batchItemIds IntList readonly
AS
begin
set nocount on

    declare @uploadFailureId int
    declare @now datetimeoffset = sysDateTimeOffset()


    insert into XLedgerTransactionUploadFailure
    (
        FailedAt,
        ErrorMessage,
        XLedgerTransactionUploadFailureLocationFid,
        TransactionsPosted,
        XLedgerJournalEntryBatchFid
    )
    select
        FailedAt = @now,
        ErrorMessage = @exception,
        XLedgerTransactionUploadFailureLocationId = XLedgerTransactionUploadFailureLocation.XLedgerTransactionUploadFailureLocationId,
        TransactionsPosted = @transactionsPosted,
        @batchId
    from XLedgerTransactionUploadFailureLocation
    where XLedgerTransactionUploadFailureLocation.[Description] = @failureLocation

    set @uploadFailureId = scope_identity()

    update XLedgerJournalEntryBatchItem set
        XLedgerTransactionUploadFailureFid = @uploadFailureId
    from @batchItemIds Items
    inner join XLedgerJournalEntryBatchItem on XLedgerJournalEntryBatchItem.XLedgerJournalEntryBatchItemId = Items.Item

    insert into XLedgerTransactionUploadFailureSysUserMap
    (
        SysUserFid,
        XLedgerTransactionUploadFailureFid
    )
    select
        XLedgerJournalEntryBatch.SubmittedBySysUserFid,
        @uploadFailureId
    from XLedgerJournalEntryBatch
    where
        XLedgerJournalEntryBatchId = @batchId
        and XLedgerJournalEntryBatch.SubmittedBySysUserFid is not null -- if there's no user then don't insert.
end
GO
GRANT EXECUTE ON  [dbo].[XLedgerMarkTransactionsPostAsFailure] TO [MssExec]
GO
Uses