web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Jesús Almaraz blog / Customizing AL snippet tEve...

Customizing AL snippet tEventSub

Jalmaraz Profile Picture Jalmaraz 669
In this post I want to show these items:
> How to customize an existing AL snippet to fit it better in your company needs.
> Show a customizing example with teventsub standard snippet
> Explain why I don´t like teventsub snippet and why I want to change it, as example.

Customizing an existing Al snippet

We will discuss the need of do that in further paragraphs, but if you want to change the behavior of an existing snippet you must follow these steps:
> Go to Preferences \ User snippets and select al in the command palette.
> Copy in this file the snippet you want to change. You can find it in the AL code repo in AL/snippets at master · microsoft/AL (github.com)
>Copy snippet code into al.json file opened.
>Edit your customizations in the file. If you need some help about snippets customizations, you can see some previous posts:

Example teventsub customization

> Copy in this file the snippet you want to change. You can find it in the AL code repo in AL/snippets at master · microsoft/AL (github.com) I opened in the repo al.json because this repo file contains TEventSub snippet.
2273.aljson.png
I select the snippet lines and copy in the next step.
>> Go to Preferences \ User snippets and select al in the command palette. In the open file you can paste the snippet code:
{    "Snippet: Event Subscriber": {
    "prefix": "teventsub",
    "body": [
        "[EventSubscriber(ObjectType::${1|Codeunit,Page,Query,Report,Table,XmlPort|}, ${2|Codeunit::,Database::,Page::,Query::,Report::,XmlPort::|}, ${3:'OnSomeEvent'},
        "local procedure ${7:MyProcedure}(${8})",
        "begin",
        "\t$0",
        "end;"
    ],
    "description": "Snippet: Event Subscriber"
},
>Edit your customizations in the file. I replaced this part of the snippet:
${5:SkipOnMissingLicense}, ${6:SkipOnMissingPermission})]",
By this one:
false, false)]",
> Save the al.json file.

Why skip permission error is a bad way. Break it early

The first step to break down snippet change is to explain what means skip permission error in event subscriptions, its last two parameters. If you set them to true, and the user or license doesn´t have permission to current subscriber object, the permission error will ne skipped (great) but the subscription execution too (not so great). So, if you set these values to true, you can be asking for hours why your subscription code doesn´t work and never raises and begin debugging until you become crazy.
So, as strong believer in “Break it early” principle, I´d rather set both properties to false and suggest all my fellow workers to do the same. When is set to false you will have an honest and direct error instead a bunch of doubts.
Last thoughts:
 > Avoid copy all the snippets in your customized al snippets file, only ones you are sure to change. Your customized snippet will not be updated with next al language extension release. In fact, they will be updated, but you always will work with your own version of them, until you remove it.
> This can help to set or suggest in your company work rules or patterns. In this case you can leave your customized al snippet file in a shared folder.

Comments

*This post is locked for comments