Design ER expressions to call application class methods
This article describes how to reuse the existing application logic in Electronic reporting (ER) configurations by calling required methods of application classes in ER expressions. Values of arguments for calling classes can be dynamically defined at runtime. For example, values can be based on information in the parsing document, to ensure its correctness.
For the example in this article, you will design a process that parses incoming bank statements for an application data update. You will receive the incoming bank statements as text (.txt) files that contain International Bank Account Number (IBAN) codes. As part of the process of importing the bank statements, you must validate the correctness of the IBAN code by using the logic that is already available.
Prerequisites
The procedures in this article are intended for users who have been assigned the System administrator or Electronic reporting developer role.
The procedures can be completed by using any data set.
To complete them, you must download and save the following file: SampleIncomingMessage.txt.
In this article, you will create the required ER configurations for the Litware, Inc. sample company. Therefore, before you complete the procedures in this article, you must follow these steps.
- Go to Organization administration > Workspaces > Electronic reporting.
- On the Localization configurations page, verify that the configuration provider for the Litware, Inc. sample company is available and marked as active. If you don't see this configuration provider, you must first complete the steps in Create configuration providers and mark them as active.
Import a new ER model configuration
On the Localization configurations page, in the Configuration providers section, select the tile for the Microsoft configuration provider.
Select Repositories.
On the Localization repositories page, select Show filters.
To select the Global repository record, add a Name filter field.
In the Name field, enter Global. Then select the contains filter operator.
Select Apply.
Select Open to review the list of ER configurations in the selected repository.
On the Configuration repository page, in the configuration tree, select Payment model.
On the Versions FastTab, if the Import button is available, select it, and then select Yes.
If the Import button isn't available, you've already imported the selected version of the Payment model ER configuration.
Close the Configuration repository page, and then close the Localization repositories page.
Add a new ER format configuration
Add a new ER format to parse incoming bank statements in TXT format.
On the Localization configurations page, select the Reporting configurations tile.
On the Configurations page, in the configuration tree in the left pane, select Payment model.
Select Create configuration.
In the drop-down dialog box, follow these steps:
- In the New field, enter Format based on data model PaymentModel.
- In the Name field, enter Bank statement import format (sample).
- In the Supports data import field, select Yes.
- Select Create configuration to finish creating the configuration.
Design the ER format configuration – Format
Design an ER format that represents the expected structure of the external file in TXT format.
For the Bank statement import format (sample) format configuration that you added, select Designer.
On the Format designer page, in the format structure tree in the left pane, select Add root.
In the dialog box that appears, follow these steps:
- In the tree, select Text\Sequence to add a Sequence format component.
- In the Name field, enter Root.
- In the Special characters field, select New line - Windows (CR LF). Based on this setting, each line in the parsing file will be considered a separate record.
- Select OK.
Select Add.
In the dialog box that appears, follow these steps:
- In the tree, select Text\Sequence.
- In the Name field, enter Rows.
- In the Multiplicity field, select One many. Based on this setting, at least one line will be expected to be present in the parsing file.
- Select OK.
In the tree, select Root\Rows, and then select Add Sequence.
In the dialog box that appears, follow these steps:
- In the Name field, enter Fields.
- In the Multiplicity field, select Exactly one.
- Select OK.
In the tree, select Root\Rows\Fields, and then select Add.
In the dialog box that appears, follow these steps:
- In the tree, select Text\String.
- In the Name field, enter IBAN. 3.. Select OK.
Select Save.
The configuration is now set up so that each line in the parsing file contains only the IBAN code.
Design the ER format configuration – Mapping to a data model
Design an ER format mapping that uses information from the parsing file to fill in a data model.
On the Format designer page, on the Action Pane, select Map format to model.
On the Model to datasource mapping page, on the Action Pane, select New.
In the Definition field, select BankToCustomerDebitCreditNotificationInitiation.
In the Name field, enter Mapping to data model.
Select Save.
Select Designer.
On the Model mapping designer page, in the Data source types tree, select Dynamics 365 for Operations\Class.
In the Data sources section, select Add root to add a data source that calls the existing application logic for IBAN codes validation.
In the dialog box that appears, follow these steps:
- In the Name field, enter Check_codes.
- In the Class field, enter or select ISO7064.
- Select OK.
In the Data source types tree, follow these steps:
- Expand the format data source.
- Expand format\Root: Sequence(Root).
- Expand format\Root: Sequence(Root)\Rows: Sequence 1..* (Rows).
- Expand format\Root: Sequence(Root)\Rows: Sequence 1..* (Rows)\Fields: Sequence 1..1 (Fields).
In the Data model tree, follow these steps:
- Expand the Payments field of the data model.
- Expand Payments\Creditor Account(CreditorAccount).
- Expand Payments\Creditor Account(CreditorAccount)\Identification.
- Expand Payments\Creditor Account(CreditorAccount)\Identification\IBAN.
Follow these steps to bind components of the configured format to data model fields:
- Select format\Root: Sequence(Root)\Rows: Sequence 1..* (Rows).
- Select Payments.
- Select Bind. Based on this setting, each line in the parsing file will be considered a single payment.
- Select format\Root: Sequence(Root)\Rows: Sequence 1..* (Rows)\Fields: Sequence 1..1 (Fields)\IBAN: String(IBAN).
- Select Payments\Creditor Account(CreditorAccount)\Identification\IBAN.
- Select Bind. Based on this setting, the IBAN field of the data model will be filled with the value from the parsing file.
On the Validations tab, follow these steps to add a validation rule that shows an error message for any line in the parsing file that contains an invalid IBAN code:
- Select New, and then select Edit condition.
- On the Formula designer page, in the Data source tree, expand the Check_codes data source that represents the ISO7064 application class to view the available methods of this class.
- Select Check_codes\verifyMOD1271_36.
- Select Add data source.
- In the Formula field, enter the following expression: Check_codes.verifyMOD1271_36(format.Root.Rows.Fields.IBAN).
- Select Save, and then close the page.
- Select Edit message.
- On the Formula designer page, in the Formula field, enter CONCATENATE("Invalid IBAN code has been found: ", format.Root.Rows.Fields.IBAN).
- Select Save, and then close the page.
Based on these settings, the validation condition will return FALSE for any invalid IBAN code by calling the existing verifyMOD1271_36 method of the ISO7064 application class. Note that the value of the IBAN code is dynamically defined at runtime as the argument of the calling method, based on the content of the parsing text file.
Select Save.
Close the Model mapping designer page, and then close the Model to datasource mapping page.
Run the format mapping
For testing purposes, run the format mapping by using the SampleIncomingMessage.txt file that you downloaded earlier. The generated output will include data that is imported from the selected text file and ported to the custom data model during the real import.
On the Model to datasource mapping page, select Run.
On the Electronic report parameters page, select Browse, browse to the SampleIncomingMessage.txt file that you downloaded, and select it.
Select OK.
Notice that the Model to datasource mapping page shows an error message about an invalid IBAN code.
Review the output in XML format that represents the data that has been imported from the selected file and ported to the data model. Notice that only three lines of the imported text file were processed without errors. The IBAN code on line 4 isn't valid and was skipped.