Please enable JavaScript to view this site.

 

Navigation: Zetadocs Expenses SDK Guide > SDK API

OnAfterCreatePurchaseLine

Scroll Prev Top Next More

OnAfterCreatePurchaseLine Event 

This event will allow you to make amendments to the Purchase Line for the expense item currently being processed (each expense item is processed one at a time in a sequential manner).

Publisher

[IntegrationEvent(false, false)]

procedure OnAfterCreatePurchaseLine(var onAfterCreatePurchaseLine: Codeunit "Zde OnAfter Create Purch. Ln")

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", 'OnAfterCreatePurchaseLine', '', 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 Purch. Ln codeunit

This codeunit exposes procedures that allow the Purchase Invoice 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 OnAfterCreatePurchaseLine data type.

 

Method name 

Description 

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

Returns the Expense Export Data for the expense item that has been processed.

GetPurchaseLine (var purchaseLine: Record "Purchase Line")

Returns the current Purchase Line.

UpdatePurchaseLine (purchaseLine: Record "Purchase Line")

Sets new data into the Purchase Line

TryUpdatePurchaseLine (purchaseLine: Record "Purchase Line"): Boolean

Sets new data into the Purchase Line. Returns the result of the operation as a Boolean.

GetPurchaseLineNonTaxable (var purchaseLineNonTaxable: Record "Purchase Line")

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

UpdatePurchaseLineNonTaxable (purchaseLineNonTaxable: Record "Purchase Line")

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

TryUpdatePurchaseLineNonTaxable (purchaseLineNonTaxable: Record "Purchase Line"): Boolean

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

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

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

 

GetPurchaseLine Method

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

 

Syntax

onAfterCreatePurchaseLine. GetPurchaseLine(var purchaseLine: Record "Purchase Line");

 

Parameters

purchaseLine

Type: Record "Purchase Line"

Purchase Line before it is processed by the standard logic. Does not contain any data at this stage (Unless it has previously been set by the UpdatePurchaseLine method). 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.

 

UpdatePurchaseLine Method

Provides a way to set the Purchase Line with updated information. An error is thrown if an operational error is encountered when running this method.

 

Syntax

onAfterCreatePurchaseLine. UpdatePurchaseLine(purchaseLine: Record "Purchase Line");

 

Parameters

purchaseLine

Type: Record "Purchase Line"

Purchase Line modification to update.

 

TryUpdatePurchaseLine Method

Provides a way to set the Purchase Line with updated information. In this method, if an operational error is encountered, a Boolean is returned.

 

Syntax

onAfterCreatePurchaseLine. TryUpdatePurchaseLine(purchaseLine: Record "Purchase Line");

 

Parameters

purchaseLine

Type: Record "Purchase Line"

Purchase Line modification to update.

 

Returns

purchaseHeader

Type: Record "Purchase Header"

True if execution was successful, false if error occurred.

 

GetPurchaseLineNonTaxable Method

Provides a way to retrieve the Purchase Line that is currently set for the adjustment line.

 

Syntax

onAfterCreatePurchaseLine.GetPurchaseLineNonTaxable(var purchaseLineNonTaxable: Record "Purchase Line");

 

Parameters

purchaseLineNonTaxable

Type: Record "Purchase Line"

Purchase Line for the non-taxable portion of the expense item. Does not contain any data at this stage (Unless it has previously been set by the UpdatePurchaseLine method). This will generally return an empty record unless the expense item has a non-taxable portion.

 

UpdatePurchaseLineNonTaxable Method

Provides a way to set the Purchase 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

onAfterCreatePurchaseLine.UpdatePurchaseLineNonTaxable(purchaseLineNonTaxable: Record "Purchase Line");

 

Parameters

purchaseLineNonTaxable

Type: Record "Purchase Line"

Purchase Line modification to update.

 

TryUpdatePurchaseLineNonTaxable Method

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

 

Syntax

onAfterCreatePurchaseLine. TryUpdatePurchaseLine(purchaseLine: Record "Purchase Line");

 

Parameters

purchaseLine

Type: Record "Purchase Line"

Purchase Line modification to update.

 

Returns

True if execution was successful, false if error occurred.

 

SetError Method

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

 

Syntax

onAfterCreatePurchaseLine.SetError(errorMessage: Text);

 

Parameters

errorMessage

Type: Text

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

 

 

Code Example

Below is an example of how to update the Description field of a Purchase Invoice Line, so that the date value from each expense is included (along with the Expense ID, user ID of the submitter and the expense description - as it was entered by the submitter user).

Using this example code, the Description field will contain information in this format:

 “<ZetadocsExpenseID> - <ZetadocsUserID> - <ZetadocsExpenseDate> - <ZetadocsExpenseDescription>.

 

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

procedure OnAfterCreatePurchaseLine(var onAfterCreatePurchaseLine: Codeunit "Zde OnAfter Create Purch. Ln")

var

    purchaseLine: Record "Purchase Line";

    purchaseLineNonTaxableRecord "Purchase Line";

    expensesExportDataCodeunit "Zde Export Data Integration";

    newDescriptionText;

begin

    //Get the Expenses Data and Purchase Line

    onAfterCreatePurchaseLine.GetExpensesExportData(expensesExportData);

    onAfterCreatePurchaseLine.GetPurchaseLine(purchaseLine);

    onAfterCreatePurchaseLine.GetPurchaseLineNonTaxable(purchaseLineNonTaxable);

 

    //Update Purchase line description

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

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

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

        purchaseLine.Description := TruncateToField(newDescriptionpurchaseLine.Description'');

        onAfterCreatePurchaseLine.UpdatePurchaseLine(purchaseLine);

    end;

 

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

    if ((purchaseLineNonTaxable."Document No." > ''and (purchaseLineNonTaxable."Line No." > 0)) then begin

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

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

        purchaseLineNonTaxable.Description := TruncateToField(newDescriptionpurchaseLineNonTaxable.Description'- Adj.');

        onAfterCreatePurchaseLine.UpdatePurchaseLineNonTaxable(purchaseLineNonTaxable);

    end;

end;

 

 

 

Below is an example of how to update Description 2 field of a Purchase Line, the value is taken from the Notes field on an expense item and assigned to the Description 2 field:

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

    procedure OnAfterCreatePurchaseLine(var onAfterCreatePurchaseLine: Codeunit "Zde OnAfter Create Purch. Ln")

    var

        purchaseLine: Record "Purchase Line";

        expensesExportDataCodeunit "Zde Export Data Integration";

        expenseNotesText;

    begin

        onAfterCreatePurchaseLine.GetExpensesExportData(expensesExportData);

        if expensesExportData.TryGetExpenseNotes(expenseNotes) then begin

            onAfterCreatePurchaseLine.GetPurchaseLine(purchaseLine);

            purchaseLine."Description 2" := expenseNotes;

            onAfterCreatePurchaseLine.UpdatePurchaseLine(purchaseLine);

        end;

    end;