change nav 1-patterns formatting

This commit is contained in:
christianbraeunlich 2021-12-05 19:02:27 +01:00
parent ba12637e35
commit 7e4e21d223
54 changed files with 211 additions and 250 deletions

View file

@ -14,8 +14,8 @@ Missing, invalid or incomplete data is a common issue during data processing in
This article describes how to use the Error Message component in NAV, which in short gives you the possibility to:
1\. Link an error message to the page which enables you to resolve the problem.
2\. Assemble all error messages in one central view instead of having to encounter them one by one.
1. Link an error message to the page which enables you to resolve the problem.
2. Assemble all error messages in one central view instead of having to encounter them one by one.
Validating data is a common task during data processing in NAV. Unfortunately, validation is often done using NAV's integrated ERROR and TESTFIELD functions, which halt execution of the process. The user will then have to locate the invalid / missing data, correct it and reinitiate the process, possibly running into the next error, making the cycle repeat itself. This can be a very tedious, time-consuming and frustrating process. The error message component aims at improving this experience by providing a lightweight framework for error message logging and this article will explain how to leverage this functionality in your code. By doing so, all error messages are gathered during (pre-)processing and are finally presented to the user. The user then has the possibility to click on the error message, which will open the record where the invalid / missing data is located, thereby enabling the user to correct all mistakes efficiently, from one central place and in one go.
@ -31,13 +31,13 @@ By clicking on the error message, the user will be presented with the entity, wh
In the processing function, define a temporary record of type "Error Message". Use the functions on that record to populate the record with error message, a few of them being:
* **LogIfEmpty******
* **LogIfLengthExceeded******
* **LogIfInvalidCharacters******
* **LogIfOutsideRange******
* **LogIfGreaterThan******
* **LogIfEqualTo******
* **LogMessage******
* **LogIfEmpty**
* **LogIfLengthExceeded**
* **LogIfInvalidCharacters**
* **LogIfOutsideRange**
* **LogIfGreaterThan**
* **LogIfEqualTo**
* **LogMessage**
The following parameters must be provided to these functions:
@ -52,38 +52,40 @@ When the processing is complete, you can check if any error messages of type "Er
The code below is an example of how the error message component was used in one part of the before mentioned Mexican feature. This code iterates over all G/L Accounts and pipes information out into an XML file. While doing so, it is validated that all mandatory fields have values and meet certain conditions. And only if that is the case, is the XML document actually exported. Also notice, that an error message is logged, in case no G/L Accounts are found given the provided filters. That way, the user can be guided to setup the system correctly.
```AL
PROCEDURE ExportChartOfAccounts@1(Year@1000 : Integer;Month@1001 : Integer);
VAR
**TempErrorMessage@1003 : TEMPORARY Record 700;
**BEGIN
**TempErrorMessage.ClearLog;** // only necessary if variable is global
TempErrorMessage@1003 : TEMPORARY Record 700;
BEGIN
TempErrorMessage.ClearLog; // only necessary if variable is global
...
CreateXMLHeader(Document,RootNode,CatalogoNodeTxt,Namespace,Year,Month,'1.1');
IF GLAccount.FINDSET THEN BEGIN
REPEAT
**TempErrorMessage.LogIfEmpty (GLAccount,GLAccount.FIELDNO(Name),TempErrorMessage."Message Type"::Error);
**
XMLDOMManagement.AddElement(RootNode,'Ctas','',Namespace,Node);
XMLDOMManagement.AddAttribute(Node,'CodAgrup',GLAccount."SAT Account Code");
...
CASE GLAccount."Debit/Credit" OF
GLAccount."Debit/Credit"::Debit:
XMLDOMManagement.AddAttribute(Node,'Natur','D');
GLAccount."Debit/Credit"::Credit:
XMLDOMManagement.AddAttribute(Node,'Natur','A');
ELSE
**TempErrorMessage.LogMessage(
GLAccount,GLAccount.FIELDNO("Debit/Credit"),TempErrorMessage."Message Type"::Error,
STRSUBSTNO(GLAccountTypeErr,GLAccount."Debit/Credit",GLAccount.RECORDID));
** END;
UNTIL GLAccount.NEXT = 0;
REPEAT
TempErrorMessage.LogIfEmpty (GLAccount,GLAccount.FIELDNO(Name),TempErrorMessage."Message Type"::Error);
XMLDOMManagement.AddElement(RootNode,'Ctas','',Namespace,Node);
XMLDOMManagement.AddAttribute(Node,'CodAgrup',GLAccount."SAT Account Code");
...
CASE GLAccount."Debit/Credit" OF
GLAccount."Debit/Credit"::Debit:
XMLDOMManagement.AddAttribute(Node,'Natur','D');
GLAccount."Debit/Credit"::Credit:
XMLDOMManagement.AddAttribute(Node,'Natur','A');
ELSE
TempErrorMessage.LogMessage(
GLAccount,GLAccount.FIELDNO("Debit/Credit"),TempErrorMessage."Message Type"::Error,
STRSUBSTNO(GLAccountTypeErr,GLAccount."Debit/Credit",GLAccount.RECORDID));
END;
UNTIL GLAccount.NEXT = 0;
END ELSE
**TempErrorMessage.LogSimpleMessage(TempErrorMessage."Message Type"::Error,NoSATAccountDefinedErr);
**
**IF NOT TempErrorMessage.HasErrors(TRUE) THEN
** SaveXMLToClient(Document,Year,Month,'CT');
**TempErrorMessage.ShowErrorMessages(FALSE);
**END;
TempErrorMessage.LogSimpleMessage(TempErrorMessage."Message Type"::Error,NoSATAccountDefinedErr);
IF NOT TempErrorMessage.HasErrors(TRUE) THEN
SaveXMLToClient(Document,Year,Month,'CT');
TempErrorMessage.ShowErrorMessages(FALSE);
END;
```
One could also do pre-processing in a function of its own, and only if the pre-processing results in no error messages of type "Error" would the processing continue.