Please enable JavaScript to view this site.

 

Navigation: Zetadocs Expenses SDK Guide > SDK API

OnAfterCreateJournalLine

Scroll Prev Top Next More

OnAfterCreateJournalLine Event 

After an expense item is processed, this event will allow you to update the data for the General Journal Line.

Publisher

[IntegrationEvent(false, false)]

procedure OnAfterCreateJournalLine(var onAfterCreateJournalLine: Codeunit "Zde OnAfter Create Jnl. Line")

begin

end;

 

Subscriber

To subscribe to this event, you will need to decorate the subscriber method with the correct EventSubscriber attributes:

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Zetadocs Expenses Customize", 'OnAfterCreateJournalLine', '', true, true)]

 

Adjustment lines

If the expense item contains an amount which is not fully taxable, then 2 lines are created for the expense item. The first line contains the taxable amount with standard rate codes set, the second line contains the non-taxable amount with zero rate codes set.

To deal with any issues relating to differences in how Business Central may be set up to handle rounding of values, an additional adjustment line may be created once all the expense items have been processed in the Expense Data Bundle. Creation of this line can be treated in a similar way to a normal Purchase Line, and will trigger the same events.

 

Zde OnAfter Create Jnl. Ln codeunit

This codeunit exposes procedures that allow the Journal Line values after the standard processing occurs on an expense item, as well as giving access to the expenses export data. The following methods are currently available on instances of the OnAfterCreateJournalLine data type.

Method name 

Description 

GetExpensesExportData (var exportData: Codeunit "Zde Export Data Integration")

Returns the Expense Export Data for the expense item that is about to be processed.

GetGLJournalLine (var journalLine: Record "Gen. Journal Line")

Returns the current General Journal Line.

UpdateGLJournalLine (journalLine: Record "Gen. Journal Line")

Sets new data into the General Journal Line.

GetGLJournalAdjustmentLine (var journalAdjustmentLine: Record "Gen. Journal Line")

Returns the Journal Line for the non-taxable adjustment line.

UpdateGLJournalAdjustmentLine (journalAdjustmentLine: Record "Gen. Journal Line")

Sets new data for the Journal Line relating to the non-taxable adjustment line.

TryUpdateGLJournalAdjustmentLine (journalAdjustmentLine: Record "Gen. Journal Line"): Boolean

Sets new data for the Journal Line relating to the non-taxable adjustment line. Returns the result of the operation as a Boolean.

DoesJournalAdjustmentLineExist (): Boolean

Checks if an adjustment line exists for current expense item.

SetError (errorMessage: Text)

Allows setting of a custom error message.

Init()

This method is called internally by the publisher, a call to this method will return an error.

Code Example


 

GetExpensesExportData Method

Provides a way to retrieve Expense Data for the current expense item from the Export Bundle.

 

Syntax

onAfterCreateJournalLine.GetExpensesExportData (var exportData: Codeunit "Zde Export Data Integration");

 

Parameters

exportData

Type: Codeunit "Zde Export Data Integration"

This codeunit gives you read access to all the values for the current expense item.

 

GetGLJournalLine Method

Provides a way to retrieve the General Journal Line that is currently set.

 

Syntax

onAfterCreateJournalLine. GetGLJournalLine(var journalLine: Record "Gen. Journal Line");

 

Parameters

journalLine

Type: Record "Gen. Journal Line"

General Journal Line after processing by the standard logic. For an expense item with part of the amount being taxable it will be the taxable part. For taxable expense it will be taxable amount. For a non-taxable expense item, it will be the non-taxable amount. For a final report adjustment it will be the adjustment’s non-taxable amount.

 

UpdateGLJournalLine Method

Provides a way to set the General Journal Line with updated information.

 

Syntax

onAfterCreateJournalLine. UpdateGLJournalLine(journalLine: Record "Gen. Journal Line");

 

Parameters

journalLine

Type: Record "Gen. Journal Line"

General Journal modification to update.

 

GetGLJournalAdjustmentLine Method

Provides a way to retrieve the General Journal Line for an expense item adjustment (where one was needed).

 

Syntax

onAfterCreateJournalLine.GetGLJournalAdjustmentLine(var journalAdjustmentLine: Record "Gen. Journal Line")");

 

Parameters

journalAdjustmentLine

Type: Record "Gen. Journal Line"

Journal Line for the non-taxable portion of the expense item. This will generally return an empty record unless the expense item has a non-taxable portion.

 

UpdateGLJournalAdjustmentLine Method

Provides a way to set the Journal Line for the non-taxable adjustment line with updated information. An error is thrown if an operational error is encountered when running this method.

 

Syntax

onAfterCreateJournalLine. UpdateGLJournalAdjustmentLine(journalAdjustmentLine: Record "Gen. Journal Line")

 

Parameters

journalAdjustmentLine

Type: Record "Gen. Journal Line"

General Journal modification to update.

 

TryUpdateGLJournalAdjustmentLine Method

Provides a way to set the Journal Line for the non-taxable adjustment line with updated information. In this method, if an operational error is encountered, a Boolean is returned

 

Syntax

onAfterCreateJournalLine. TryUpdateGLJournalAdjustmentLine(journalAdjustmentLine: Record "Gen. Journal Line");

 

Parameters

journalAdjustmentLine

Type: Record "Gen. Journal Line"

General Journal Line modification to update.

 

Returns

True if execution was successful, false if error occurred.

 

DoesJournalAdjustmentLineExist Method

Checks if an adjustment line exists for current expense item

 

Syntax

onAfterCreateJournalLine. DoesJournalAdjustmentLineExist ();

 

Returns

True if operation adjustment line exists, false if not.

 

SetError Method

Use this method to set custom error messages that will be populated in the Expense Report.

 

Syntax

onAfterCreateJournalLine.SetError(errorMessage: Text);

 

Parameters

errorMessage

Type: Text

The error message to display to the user in the Export Report.

 

 

Code Example

The following is an example of how to update the description field in the same way when exporting expenses as a journal entry:  

[EventSubscriber(ObjectType::CodeunitCodeunit::"Zetadocs Expenses Customize"'OnAfterCreateJournalLine'''truetrue)]

procedure OnAfterCreateJournalLine(var onAfterCreateJournalLineCodeunit "Zde OnAfter Create Jnl. Line")

var

    journalLineRecord "Gen. Journal Line";

    adjJournalLineRecord "Gen. Journal Line";

    expenseDataCodeunit "Zde Export Data Integration";

    newDescriptionText;

begin

    //Get the Expenses Data and Journal Line 

    onAfterCreateJournalLine.GetExpensesExportData(expenseData);

    onAfterCreateJournalLine.GetGLJournalLine(journalLine);

 

    //Update Journal Line description

    if (journalLine."Document No." <> ''then begin

        newDescription := Format(expenseData.GetExpenseShortId()) + ' - ' + expenseData.GetReportSubmitterId()

        + ' - ' + Format(expenseData.GetExpenseTransactionDate()) + ' - ' + expenseData.GetExpenseDescription();

        journalLine.Description := TruncateToField(newDescriptionjournalLine.Description'');

        onAfterCreateJournalLine.UpdateGLJournalLine(journalLine);

    end;

 

    //Check to see if an adjustment line was created, if so update that description as well

    if (onAfterCreateJournalLine.DoesJournalAdjustmentLineExist()) then begin

        onAfterCreateJournalLine.GetGLJournalAdjustmentLine(adjJournalLine);

        newDescription := Format(expenseData.GetExpenseShortId()) + ' - ' + expenseData.GetReportSubmitterId()

        + ' - ' + Format(expenseData.GetExpenseTransactionDate()) + ' - ' + expenseData.GetExpenseDescription();

        adjJournalLine.Description := TruncateToField(newDescriptionadjJournalLine.Description'- Adj.');

        onAfterCreateJournalLine.UpdateGLJournalAdjustmentLine(adjJournalLine);

    end;

end;

 

 

Access Custom Properties Example

Below is an example how to access custom properties. Properties are iterated and if property with name Job line type equals Budget then G/L account number will be set to 8210:

[EventSubscriber(ObjectType::CodeunitCodeunit::"Zetadocs Expenses Customize", 'OnAfterCreateJournalLine''', true, true)]

    procedure OnAfterCreateJournalLine(var onAfterCreateJournalLine: Codeunit "Zde OnAfter Create Jnl. Line")

    var

        journalLine: Record "Gen. Journal Line";

        expenseData: Codeunit "Zde Export Data Integration";

        Property: JsonObject;

        PropertyJToken: JsonToken;

        ValueJToken: JsonToken;

        PropertyName: Text;

        PropertyValue: Text;

    begin

        onAfterCreateJournalLine.GetExpensesExportData(expenseData);

        onAfterCreateJournalLine.GetGLJournalLine(journalLine);

 

        foreach PropertyJToken in expenseData.GetExpenseProperties() do begin

            Property := PropertyJToken.AsObject();

 

            Property.Get('Name', ValueJToken);

            PropertyName := ValueJToken.AsValue().AsText();

            Property.Get('Value', ValueJToken);

            PropertyValue := ValueJToken.AsValue().AsText();

 

            if (PropertyName = 'Job line type') and (PropertyValue = 'Budget'then begin

                journalLine."Account No." := '8210';

            end;

        end;

 

        onAfterCreateJournalLine.UpdateGLJournalLine(journalLine);

    end;