Export Integration

These links take you to the individual sections on this page:

General

After successful document processing in the Response object, EASY Invoice Connector returns the document number in Microsoft Dynamics 365 Business Central.

If export has not been successful, you will have to respond appropriately regarding components.

Error reporting component

Possible errors

HTTP return codes

Handling the error message

XMLHTTPRequest / network
(https://otris.software/documents/api/portalscript/XMLHTTPRequest.html#open)

URL cannot be reached (network not available, host not available, etc.)

tbd

Suggestion when using a DataTool: You have to trap the error that is generated when executing the DataTool in your own code. See APIDOC de.easy.ehrm.classes.DataTools#execute

Microsoft Dynamics 365 Business Central

  • Login failed

  • Tenant not available

  • Web service / page not found

List at https://docs.microsoft.com/en-us/dynamics-nav/api-reference/v2.0/dynamics_error_codes

400 - 599

Suggestion when using a DataTool: You have to trap the error that is generated when executing the DataTool in your own code. See APIDOC de.easy.ehrm.classes.DataTools#execute

EASY for Dynamics 365 Invoice Connector

  • Required field does not exist

  • Workflow IDs already exist

200 - 299

The Response object includes the Message property that contains the error text


To achieve successful export, you have to export at least the following fields with values:

Process

EASY Invoice document type

Headers

Line item detail

Purchase invoice with reference to a purchase order (and posted goods receipts)

or

Purchase credit memo with reference to purchase return order (and posted goods returns)

RMB, GMB

  • Buy-from Vendor No.

  • Vendor Invoice No.

  • Vendor Cr. Memo No.

  • ECM Workflow Doc. Type

  • ECM Document ID (Barcode)

  • ECM Workflow Document ID

  • ECM Order- Return Order No.

  • ECM Amount Workflow

  • ECM Amount incl. VAT Workflow

  • Type

  • No.

  • Quantity

  • Direct Unit Cost

  • ECM Receipt- Return Shpd. No.

  • ECM ReceiptReturnShpd. LineNo.

  • ECM Order- Return Order No.

  • ECM Order- ReturnOrder LineNo.

Purchase invoice without reference to a purchase order

or

Purchase credit memo without reference to purchase return order

ROB, GOB

  • Buy-from Vendor No.

  • Vendor Invoice No.

  • Vendor Cr. Memo No.

  • ECM Workflow Doc. Type

  • ECM Document ID (Barcode)

  • ECM Workflow Document ID

  • ECM Amount Workflow

  • ECM Amount incl. VAT Workflow

  • Type

  • No.

  • Quantity

  • Direct Unit Cost

Export DataTool

The DataTool for export (Microsoft Business Central Connector - Export) is already part of the standard package that also contains the Import and UserExit DataTools. It consists of three components:

  • the Microsoft Business Central Connector - Export DataTool itself,

  • the transformation callbackscript cb.ehrmDataTools.transform.invoice2businesscentral and

  • the Response-Handler-Script cb.ehrmDataTools.handler.invoice2businesscentral

The DataTool is configured such that it expects an individual file of the epiFiles file type for execution. The fields configured in the Simple selection are read from the invoice data file, transformed in the Transformation callbackscript (e.g. customizing the date format), and passed to the EASY Invoice Connector's Web service. To do this, the environment variables set for the DataTool or added to runtime are inserted in the URL. The Response Handler script processes the Microsoft Dynamics 365 Business Central or EASY Invoice Connector response by either writing back the document number (ERPProcessNumber field) or the error message (ExportServerInfo field) to the invoice data file.

Customizations to the DataTool

At least the following customizations to the Export DataTool are requried for successfully running the DataTool:

  • User field on file cover, sectionTarget service

  • Password field on file cover, section Target service

  • Environment variables field on theAdvanced tab, section Scripting

    • apiversion Specify the API version to be used (as of March 2021): v2.0)

    • tenant: Specify the GUID of your Business Central Tenant

    • system: Specify the name of the system to be used

Customizations to the Transformation callbackscript

All minimum required and some of the optional fields have already been integrated, so the script should be executable without major customizations. If, however, customizations and extensions are necessary, please look at the example on Project-Specific Customizations.

Customizations to the Response Handler

You should be able to use the script unmodified. Customize it to your needs only in exceptional cases.

Notes to integration

  • Organize export after final release of the invoice/credit memo.

    • One variant is to organize export via public folders, as suggested in the sample integration.

    • But a script call at the end of the project-specific part of your approval workflow is also an option. You will then have to handle possible server responses in the workflow.

      Sample code for script call
      //#import cached [de.easy.ehrm.library.Standalone]
      try {
      const cFile = context.file;
      if (!cFile) throw new Error("no file in context.");
      const uniqueId = "de.easy.bcc.export.CHANGE_ME"; // please change this variable to the chosen unique id (advanced tab) of the respective export data tool
      const dt = new de.easy.ehrm.classes.DataToolsFactory.createByUniqueId(uniqueId, cFile),
      env = dt.getEnvironmentVariables();
      env.company = cFile.Recipient;
      dt.getDestinationService().addContext(env);
      dt.execute();
      }
      catch (ex) { c
      File.ExportServerInfo = ex;
      cFile.sync();
      util.log("execution failed. " + ex);
      }
    • The Export DataTool can also be configured as an action for the epiFiles file typed (Export DataTool, File cover, Configure action checkbox in the section Source). If this is the preferred option, you should ensure by using an AllowedActions script that the action is displayed only depending on specific conditions.

  • To avoid discrepancies between the purchase invoices posted in "Microsoft Dynamics 365 Business Central" and the archive EASY Invoice purchase invoices, you should query the "Microsoft Dynamics 365 Business Central" table of the posted purchase invoices via the file ID of the current workflow and update the Documents file prior to archiving the invoice data file.

Sample integration

The following components and processes are just a suggestion of how to integrate purchase invoice data export to EASY Invoice Connector with an existing EASY Invoice workflow.

How it works

Three public folders are used to control exporting EASY Invoice invoices and credit memos:

  • Passing ERP

  • Exported to ERP

  • ERP transfer corrupt

All purchase invoices and credit memos ready for export are displayed in the Transfer ERP folder. For this purpose, two filters are used (ExportServerInfo empty and ERPProcessNumber empty). The filters need to be extended by at least a third criterion according to the process in your environment to prevent unintentional export of processes not yet released.

The Export action is available for the Transfer ERP folder. It allows you to select an Export DataTool and individually executes the Export DataTool for all selected processes. All DataTools whose field value Unique ID on the Advanced tab begins with de.easy.bcc.export are displayed as Export DataTools. An appropriate Export DataTool already exists through the installation media installation.

Export of a process may be successful, or stopped with an error:

  • Successful exports are displayed in the Exported to ERP folder; they contain the document number specified by Dynamics 365 Business Central in the ERPProcessNumber file field.

  • Corrupt exports are displayed in the ERP transfer corrupt folder. They contain the error message in the ExportServerInfo file field; the ERPProcessNumber field is blank.

Evaluation and handling the export result varies from case to case and the responding component. The following cases are taken into consideration:

HTTP Responsecodes

Meaning

Sample response

Handling

200-299

Success

HTTP/1.1 200 OK

{
"@odata.context": "https://api.businesscentral.dynamics.com/v2.0/d4371590-0b07-46a0-a999-f93d33a63f79/DEV-Sandbox/ODataV4/$metadata#Edm.String",
"value": "{\"No.\":\"107307\",\"Status\":\"Open\",\"URL\":\"https://businesscentral.dynamics.com/d4371590-0b07-46a0-a999-f93d33a63f79/DEV-Sandbox/?company=CRONUS%20DE&page=51\",\"Message\":\"\"}"
}

The Response handler of the Export DataTool (cb.ehrmDataTools.handler.invoice2businesscentral) writes the document's number (No.) in the ERPProcessNumber field of the purchase invoice file used to launch the Export DataTool.

200-299

Error

HTTP/1.1 200 OK

{
"@odata.context": "https://api.businesscentral.dynamics.com/v2.0/d4371590-0b07-46a0-a999-f93d33a63f79/DEV-Sandbox/ODataV4/$metadata#Edm.String",
"value": "{\"No.\":\"107308\",\"Status\":\"Open\",\"URL\":\"https://businesscentral.dynamics.com/d4371590-0b07-46a0-a999-f93d33a63f79/DEV-Sandbox/?company=CRONUS%20DE&page=51&filter='ECM%20Workflow%20Document%20ID'%20IS%20'777777_fi20210081187735'\",\"Message\":\"The field Buy-from Vendor No. of table Purchase Header contains a value (50001) that cannot be found in the related table (Vendor).\"}"
}

The Response handler of the Export DataTool (cb.ehrmDataTools.handler.invoice2businesscentral) writes the error message from the "Message" field in the file field ExportServerInfo of the purchase invoice.

400-499

Client error

HTTP/1.1 404 Not Found

{
"error": {
"code": "BadRequest_NotFound",
"message": "Resource not found for the segment 'ECM_InvoiceJSONWebService_GetWorkflowDocument'. CorrelationId b97ac86c-c599-4c32-8a5f-d711f7b61f57."
}
}

The PortalScript executing the Export DataTool (de.easy.bcc.example.exportPostingData) writes the error message in the file field ExportServerInfo

500-599

Server error

HTTP/1.1 503

{
"error": {
"code": "Application_ServiceUnavailable",
"message": "The tenant 'msweua1602t24422181' is not accessible. CorrelationId 9fc39271-2134-4674-8a80-209005a949ac."
}
}

The PortalScript executing the Export DataTool (de.easy.bcc.example.exportPostingData) writes the error message in the file field ExportServerInfo

Installation and configuration

The necessary imports can be found in the example folder of the installation media. Proceed as follows:

  1. Import the xml files for Public folders which you find in the /example/folder folder, using the Documents5 Manager

  2. Define an existing accounting entity folder as a parent folder for the folders you have just imported (folders for accounting entities can be found below the epiData folder )

  3. Import the xml file for the PortalScripts

  4. Note minimum configuration of the Export DataTool (chap. Export DataTool)