Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Jesús Almaraz blog / Custom diagnostics: regex h...

Custom diagnostics: regex help and new use case

Jalmaraz Profile Picture Jalmaraz 669

This post is the follow-up of these posts

New bulk replacing VSCode extension - Dynamics 365 Business Central Community

How to set your own VSCode diagnostics (Replacing tool 2) - Dynamics 365 Business Central Community

About this extension:

Custom diagnostics, bulk replacements and configurable fixes - Visual Studio Marketplace

When I began using my own extension, I increased work pace converting BC old versions to new ones.

But in this post I will focus on the challenges and difficulties of the extension: A-the possible uses are so wide that it is hard to detect use cases. B-Write regex in .json objects. Writing a regex in a .json object is not easy: in addition to the complexities of defining regular expressions, you must escape the expression before writing it in a json value. I mean:

"searchExpresion": "field\(\d+;.+ No."; Code\[10\]",//ERRORRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

So, you must fix the expression escaping it this way:

"searchExpresion": "field\\(\\d+;.+ No.\"; Code\\[10\\]",

Finding solutions

For me was important to ease regex handling:

As we can see in the gif below, we have important help in the context menu to create regex faster: “JAM Custom Rules. Open regex help URL in explorer” and “JAM Custom Rules. Paste escaped clipboard content”:

regexHelp.gif

Another use case. Detect wrong field lengths

We have a lot of pain when in an AppSource published extension we have to increase the length of a field which is part of the primary key: simply you can´t.

You must obsolete the table and create a new one and make upgrade code to transfer old table content to new one. Example:

field(5; "Customer No."; Code[10])

To avoid this kind of publishing, I created a new diagnostic this way:

        {
            "code": "JAMMIG005",
            "message": "Revisar la longitud del campo. Si es correcto a 10 poner un comentario 'Revisada longitud' en la misma línea al final",
            "searchExpresion": "field\\(\\d+;.+No\\.\";\\s*Code\\[10\\]\\)",
            "skipFromSearchIfMatch": "Revisada longitud",
            "severity": "error",
            "language": "al"
        }

The breakdown of this diagnostic is:

When a new field whose name ended in No.” literal, and is Code type with length 10, displays in Problems Panel "Revisar la longitud del campo. Si es correcto a 10 poner un comentario 'Revisada longitud' en la misma línea al final" (in English “Review field lengthIf OK on 10, place a comment 'Revisada longitud' in the same line”.

In diagnostics extension you can set a condition to exclude form diagnostic. So if we write 'Revisada longitud' as comment in the same line, the diagnostic will be removed from Problems Panel:

removeProblem.gif

So ,when the problem raises, we can deal it with these options:

. Set field length to 20.

. If it is alright to 10, place a comment in the same line as shown above to avoid further diagnostic displaying.

 

This use case avoided a lot of pain in AppSource maintenance.

 

 

Comments

*This post is locked for comments