This event can be used to modify the Import data bundle before being Imported into Zetadocs Expenses
Publisher
[IntegrationEvent(false, false)]
procedure OnAfterImport(var onAfterImport: Codeunit "Zde OnAfter Import")
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", 'OnAfterImport', '', true, true)]
This codeunit exposes procedures that allows you to check the type of Import being executed, as well as modify the data. The following methods are currently available on instances of the OnBeforeImport data type.
Method name |
Description |
---|---|
GetImportType (var ImportType: Enum ZdeImportType) |
Returns the type of Import being executed. |
GetJobData () |
Retrieves the JsonArray of Jobs being Imported. |
Retrieves the JsonArray of Dimensions being Imported. |
|
SetJobData (jobData: JsonArray) |
Use this method to set the Import data to use for Jobs. |
SetDimensionData (dimensionData: JsonArray) |
Use this method to set the Import data to use for Dimensions. |
AddJobDataToImport (Index: Integer; JobNumber: Code[20]; JobDescription: Text; JobTasks: JsonArray) |
Use this method to add a new Job Object to the existing Import Data. |
CreateJobTaskJsonObject (TaskNumber: Code[20]; TaskDescription: Text; TaskGroup: Text) |
Use this method to create a Job Task Object. |
AddDimensionDataToImport (Index: Integer; DimensionCode: Code[20]; DimensionDescription: Text; DimensionNumber: Integer; DimensionValues: JsonArray) |
Use this method to add a new Dimension Object to the existing Import Data. |
CreateDimensionValueJsonObject(DimensionCode: Code[20]; DimensionName: Text; DimensionGroup: Text) |
Use this method to create a Dimension Value Object. |
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. |
This method returns an enum (ZdeImportType) which allows you to check the type of Import being run, current values are Jobs and Dimensions.
Syntax
importType := onAfterImportHandler.GetImportType();
This method returns a JsonArray that represents the Jobs and Tasks being Imported to Zetadocs Expenses. This JsonArray can be iterated through to get each Job, and in turn each Job Task related to that Job.
Syntax
jobArray := onAfterImportHandler.GetJobData();
This method returns a JsonArray that represents the Dimensions and Dimension Values being Imported to Zetadocs Expenses. This JsonArray can be iterated through to get each Dimension, and in turn each Dimension Value related to that Job.
Syntax
dimensionArray := onAfterImportHandler.GetDimensionData();
The Import data can be overridden with new data using this method, by passing in a JsonArray of Job objects. When using this method be sure that the Json is formatted correctly otherwise the import will fail.
Syntax
onAfterImportHandler.SetJobData(jobData);
Parameters
jobData
Type: JsonArray
The array of Job Json Objects and Job Tasks that should be Imported into Zetadocs Expenses.
The Import data can be overridden with new data using this method, by passing in a JsonArray of Dimension objects. When using this method be sure that the Json is formatted correctly otherwise the import will fail.
Syntax
onAfterImportHandler.SetDimensionData(dimensionData);
Parameters
dimensionData
Type: JsonArray
The array of Dimension Json Objects and Dimension Values that should be Imported into Zetadocs Expenses.
Use this method to add a Job data to the list of existing Jobs being imported.
Syntax
onAfterImportHandler. AddJobDataToImport (1, ‘DEERFIELD, 8 WP’, ‘Setting Up Company’, JobTasksArray);
Parameters
Index
Type: Integer
The index in the existing import array to add the new Job Object.
JobNumber
Type: Code[20]
Job Number to be imported into Zetadocs Expenses. This will be the Name displayed in the Custom Property in Zetadocs Expenses.
JobDescription
Type: Text
Job Description to be imported into Zetadocs Expenses. This will be the Display Name in the Customer Property in Zetadocs Expenses.
JobTasks
Type: JsonArray
Array of Job Task Objects related to the Job being imported. These should be created using the CreateJobTaskJsonObject method.
CreateJobTaskJsonObject Method
Use this method to create a Json Object representing a Job Task in Business Central.
Syntax
onAfterImportHandler. CreateJobTaskJsonObject (‘1000’, ‘Determining Specs’, ‘Preliminary Services’);
Parameters
TaskNumber
Type: Code[20]
The Job Task Number from Business Central. This is used as the value in the customer property values list.
TaskDescription
Type: Text
The description will be used to as the display name for custom property values in Zetadocs Expenses.
TaskGroup
Type: Text
This will be the heading under which Job Tasks will be grouped under in Zetadocs Expenses.
Use this method to add Dimension data to the existing list of Dimensions being imported to Zetadocs Expenses.
Syntax
onAfterImportHandler. AddDimensionDataToImport (1, ‘CUSTOMER’, ‘Customer Group’, 1, DimensionValueArray);
Parameters
Index
Type: Integer
The index in the existing import array to add the new Dimension Object.
Dimension
Type: Code[20]
Dimension Code to be imported into Zetadocs Expenses. This will be the Name displayed in the Custom Property in Zetadocs Expenses.
DimensionDescription
Type: Text
Dimension Description to be imported into Zetadocs Expenses. This will be the Display Name in the Customer Property in Zetadocs Expenses.
DimensionNumber
Type: Text
This value represents the Shortcut Dimension Code that the Dimension belongs to, from 1-8. If the Dimension is not part of a Dimension Code then this value should be blank.
DimensionValues
Type: JsonArray
Array of Dimension Objects related to the Job being imported. These should be created using the CreateDimensionValueJsonObject method.
CreateDimensionValueJsonObject Method
Use this method to create a Json Object representing a Dimension Value in Business Central.
Syntax
onAfterImportHandler. CreateDimensionValueJsonObject (‘PRIVATE’, ‘Private’, ‘’);
Parameters
DimensionCode
Type: Code[20]
The Dimension Value Code from Business Central. This is used as the value in the customer property values list.
DimensionName
Type: Text
The Dimension Name in Business Central. This is used to as the display name for custom property values in Zetadocs Expenses.
DimensionGroup
Type: Text
This will be the heading under which Dimension Values will be grouped under in Zetadocs Expenses.
Use this method to set custom error messages that will be populated in the Expense Report.
Syntax
onAfterImportHandler.SetError(errorMessage: Text);
Parameters
errorMessage
Type: Text
The error message to display to the user in Zetadocs Expenses.
By default the Jobs/Dimensions imported into Zetadocs Expenses exclude those that have a blocked status, the example below demonstrates how the Import Data can be updated to include the Blocked Jobs/Dimensions as well.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Zetadocs Expenses Customize", 'OnAfterImport', '', true, true)]
procedure OnAfterImport(var onAfterImport: Codeunit "Zde OnAfter Import")
var
BlockedDimensions: Record Dimension;
DimensionValues: Record "Dimension Value";
BlockedJobs: Record Job;
JobTasks: Record "Job Task";
ImportType: Enum ZdeImportType;
ThisMethod: Text;
ImportData: JsonArray;
RecordToken: JsonToken;
JobTaskObject: JsonObject;
JobTaskArray: JsonArray;
JobNumber: Code[20];
DimensionValueObject: JsonObject;
DimensionValueArray: JsonArray;
DimensionValue: Code[20];
DisplayGroup: Text;
Index: Integer;
begin
ThisMethod := 'onAfterImport';
onAfterImport.GetImportType(ImportType);
case ImportType of
ImportType::Jobs:
begin
ImportData := onAfterImport.GetJobData();
//Want to add the blocked Jobs to the output as well (these are not retrieved by default).
BlockedJobs.SetFilter(Blocked, '<>%1', BlockedJobs.Blocked::" ");
if (BlockedJobs.Find('-')) then begin
//For simplicity using a Group Name of 'Blocked'
DisplayGroup := 'Blocked';
repeat
JobTasks.SetFilter("Job No.", BlockedJobs."No.");
if (JobTasks.Find('-')) then begin
repeat
begin
//Create a new Job Task to add to the Import
JobTaskObject := onAfterImport.CreateJobTaskJsonObject(JobTasks."Job No.", JobTasks.Description, DisplayGroup);
JobTaskArray.Add(JobTaskObject);
end;
until JobTasks.Next() = 0;
end;
//Only need the code below if the order is important.
//Find where this Job should be inserted in the Import.
while Index < ImportData.Count do begin
ImportData.Get(Index, RecordToken);
Index += 1;
RecordToken.AsObject().Get('JobNumber', RecordToken);
JobNumber := RecordToken.AsValue().AsCode();
if (JobNumber > BlockedJobs."No.") then begin
//Insert the new Job
onAfterImport.AddJobDataToImport(Index - 1, BlockedJobs."No.", BlockedJobs.Description, JobTaskArray);
break;
end else
if (Index >= ImportData.Count) then begin
//Insert the new Job at the end
onAfterImport.AddJobDataToImport(ImportData.Count, BlockedJobs."No.", BlockedJobs.Description, JobTaskArray);
break;
end;
end;
//New Object added so get the latest Import Data
ImportData := onAfterImport.GetJobData();
clear(JobTaskArray);
until BlockedJobs.Next() = 0;
end;
end;
ImportType::Dimensions:
begin
ImportData := onAfterImport.GetDimensionData();
//Want to add the blocked Dimensions to the output as well (these are not retrieved by default).
BlockedDimensions.SetFilter(Blocked, 'true');
if (BlockedDimensions.Find('-')) then begin
//For simplicity using a Group Name of 'Blocked'
DisplayGroup := 'Blocked';
repeat
DimensionValues.SetFilter("Dimension Code", BlockedDimensions.Code);
if (DimensionValues.Find('-')) then begin
repeat
begin
//Create a new DimensionValue to add to the Import
DimensionValueObject := onAfterImport.CreateDimensionValueJsonObject(DimensionValues.Code, DimensionValues.Name, DisplayGroup);
DimensionValueArray.Add(DimensionValueObject);
end;
until DimensionValues.Next() = 0;
end;
//Only need the code below if the order is important.
//Find where this Dimension should be inserted in the Import.
while Index < ImportData.Count do begin
ImportData.Get(Index, RecordToken);
Index += 1;
RecordToken.AsObject().Get('DimensionCode', RecordToken);
DimensionValue := RecordToken.AsValue().AsCode();
if (DimensionValue > BlockedDimensions.Code) then begin
//Insert the new Dimension
onAfterImport.AddDimensionDataToImport(Index - 1, BlockedDimensions.Code, BlockedDimensions.Name,
onAfterImport.GetDimensionNumber(BlockedDimensions.Code), DimensionValueArray);
break;
end else
if (Index >= ImportData.Count) then begin
//Insert the new Dimension at end
onAfterImport.AddDimensionDataToImport(ImportData.Count, BlockedDimensions.Code, BlockedDimensions.Name,
onAfterImport.GetDimensionNumber(BlockedDimensions.Code), DimensionValueArray);
break;
end;
end;
//New Object added so get the latest Import Data
ImportData := onAfterImport.GetDimensionData();
clear(DimensionValueArray);
until BlockedDimensions.Next() = 0;
end;
end;
end;