AL icon indicating copy to clipboard operation
AL copied to clipboard

Eventing in New Developer Environment

Open Rachit14 opened this issue 9 years ago • 11 comments

Hello,

Is field level triggers and events available currently in new Developer environment. As in screen below we cannot see the particular field level trigger in Customer Table. Neither it is available in Event Subscription function. Anybody tried this and resolved it, please share. If not I think this can be treated as bug.

image

Rachit14 avatar Jan 18 '17 09:01 Rachit14

Do you want to see Field level triggers of LinkedVendorCode field? then trigger should be added withing { } Is it what you mean?

pmohanakrishna avatar Jan 18 '17 09:01 pmohanakrishna

As @pmohanakrishna wrote, the trigger should be defined within the field definition block '{' '}'. In your case this means moving lines 11-14 to line 9

StanislawStempin avatar Jan 18 '17 09:01 StanislawStempin

@pmohanakrishna and @StanislawStempin - Thanks for your replies and explanations. Actually I was looking for Customer Table Existing Fields (ex - Name field) trigger. Can you please help me to identify the position in code where I can write and find the triggers like OnBeforeValidateEvent(CurrFieldNo) and OnAfterValidateEvent(CurrFieldNo) etc. of particular tables like Customer Table in my case?

Rachit14 avatar Jan 19 '17 04:01 Rachit14

We need to use codeunits to write subscribers it should be like [EventSubscriber(ObjectType::Table, 18, 'OnBeforeValidateEvent', 'Name',true,true)] [EventSubscriber(ObjectType::Table, 18, 'OnAfterValidateEvent', 'Name',true,true)]

Use [EventSusbscriber in your image. or teventsub snippet.

pmohanakrishna avatar Jan 19 '17 05:01 pmohanakrishna

We have added a simplified way of subscribing to the validation events in the new compiler

tableextension 70050090 CustomerExtension extends Customer
{
    fields
    {
        modify(Name) // Modify the existing name field.
        {
            // Customizable properties can be changed here.
            CaptionML = ENU = 'My Changed Caption';

            trigger OnBeforeValidate();
            begin
                // Before validating customer name
            end;

            trigger OnAfterValidate();
            begin
                // After validation customer name
            end;
        }
    }
}

Same mechanism is supported for Fields and Actions on Pages in the PageExtension object.

esbenk avatar Jan 19 '17 07:01 esbenk

Looks nice, but I'd rather call it "OnModify". That would at least give you a much clearer picture on what is going on (imho). Just details though ;-)

waldo1001 avatar Jan 19 '17 08:01 waldo1001

But it seems intellisense is not able to offer modify first time in new object and fields names in modify? Let me know if you didnt get it.

pmohanakrishna avatar Jan 19 '17 08:01 pmohanakrishna

Hm, sorry, I didn't read it carefully enough. Looks like a very different approach.. .

Pls ignore my comment and I'll try to understand it first ;-)

waldo1001 avatar Jan 19 '17 08:01 waldo1001

@pmohanakrishna The are still no keyword intellisense in the extension objects and don't have the field intellisense for the field modify() yet.

We do however already have intellisense for Field and Action lookup on pageextensions.

esbenk avatar Jan 19 '17 08:01 esbenk

On, get it now :-) (I think). I didn't like the approach.. I have never been a fan of changing properties. What happens when two apps change the same caption?

waldo1001 avatar Jan 19 '17 08:01 waldo1001

This is extension V1 functionality. Only a small subset of properties can be modified, the rest will cause compiler errors.

The conflict resolution is handled on the server. The rules are the same as for V1 extensions. At some point you will be able to personalize the caption, and thus overwriting any changes made to captions by extensions.

The is a long list of properties that can't be modified, only the ones deemed "safe" can.

For reference a list of the non-modifiable properties can be found here.

https://msdn.microsoft.com/en-us/dynamics-nav/extension-packages-capability-support-matrix

esbenk avatar Jan 19 '17 08:01 esbenk