Please enable JavaScript to view this site.

 

Code Examples

Skip Export Example

Below is an example of how to skip the Export Process depending on the type of export being performed, for Purchase Invoices the export is skipped, and for Journal it isn’t so an export will be created:

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

    procedure OnBeforeExport(var onBeforeExportHandler: Codeunit "Zde OnBefore Expenses Export") 

    var 

        ExportData: Codeunit "Zde Export Data Integration"; 

        ExportType: Enum ZdeExportType; 

        ThisMethod: Text; 

    begin 

        ThisMethod := 'OnBeforeExport'; 

        //Want to skip the default export if its a journal 

        if (onBeforeExportHandler.TryGetExportType(ExportType)) thenbegin 

            case ExportType of 

                ZdeExportType::PurchaseInvoice: 

                    begin 

                        onBeforeExportHandler.SetIsToSkip(true); 

                    end; 

                ZdeExportType::Journal: 

                    begin 

                        onBeforeExportHandler.SetIsToSkip(false); 

                    end; 

            end; 

        end; 

    end; 

 

Update Record 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 onAfterCreatePurchaseLineCodeunit "Zde OnAfter Create Purch. Ln")

var

    purchaseLineRecord "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;

 

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;

 

 

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''', true, true)]

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

    var

        purchaseLine: Record "Purchase Line";

        expensesExportData: Codeunit "Zde Export Data Integration";

        expenseNotes: Text;

    begin

        onAfterCreatePurchaseLine.GetExpensesExportData(expensesExportData);

        if expensesExportData.TryGetExpenseNotes(expenseNotesthen begin

            onAfterCreatePurchaseLine.GetPurchaseLine(purchaseLine);

            purchaseLine."Description 2" := expenseNotes;

            onAfterCreatePurchaseLine.UpdatePurchaseLine(purchaseLine);

        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;