BIG PROBLEM using events in NAV2016

marvaxmarvax Member Posts: 14
Hi,
We have decided to use events in new customizations which will reduce modifying standard objects.
But our experience has demonstrated that the use of these special events brings big problems
Indeed, events are executed randomly.
Using the debugger, we have demonstrated that NAV does not always running the events (this example is an event onafterinsert on table Sales lines).
However if we recompile the object, the event is well run .... until the next time it will not be more.
HAs someone encountered the same problem?
THanks for your repply.

Answers

  • mohana_cse06mohana_cse06 Member Posts: 5,503
    do you mean that events are some times not running?
    No, I didn't face this problem before.
    can you provide more details please.
  • marvaxmarvax Member Posts: 14
    Yes, i mean that events are some times not running.
    an example : this fonction

    [b]LOCAL [EventSubscriber] Table_36_OnAfterInsert(VAR Rec : Record "Sales Header";RunTrigger : Boolean)
    IF NOT RunTrigger THEN
    EXIT;
    [/b]
    "Created user ID" := USERID;


    The result is sometimes the field Created user ID is empty and sometimes the field is good.

    So we have put a breakpoint in this instruction , and debugging has showed that sometimes NAV goes in the event, and sometime don't go into. And when NAV don't execute event, we recompile codeunit with the event and so NAV execute correctly the event, some hours ....

  • mohana_cse06mohana_cse06 Member Posts: 5,503
    were you creating record manually?
    can you simply try with
    "Created user ID" := USERID;

    can you sync the db once or restart the service after changes.
  • marvaxmarvax Member Posts: 14
    This is a small example of code. We put lot of code in event .
    For example create recupel TAxe line. And same problem, new lines are created randomly. When the user has the problem, just recompile objet and the user hasn't more the problem. but some days or hours later the user has the problem again
    No need sync database, or restart service, just recompile the codeunit that contains the event.
  • ishwarsharma016ishwarsharma016 Member Posts: 50
    I have faced this problem in NAV 2016 CU5. What CU are you working on?
    Thanks,
    Ishwar Sharma

    My Blogs: Dynamics Community Blog | Blogspot
    Connect: Google + | Twitter
  • marvaxmarvax Member Posts: 14
    Hi ishwarsharma016,
    I have tested with CU12, and same problem :(
  • guidorobbenguidorobben Member Posts: 157
    you forgot the MODIFY. It's the after insert. So you manually have to modify the record.
  • _tg_tg Member Posts: 2
    edited 2016-10-21
    I think for OnAfterInsert etc you may need to add a modify; as it after the transactional write. if you don't want to do that look at OnBefore etc
  • marvaxmarvax Member Posts: 14
    Hi _tg, Hi guidorobben
    I have tested with modify, same problem.
    I have debugging and nav don't pass in the event !
    So any code present in the event, is executed.
  • ishwarsharma016ishwarsharma016 Member Posts: 50
    No, you don't need to add the modify because the table variable is called by reference! and it updates any changes you make.

    Is "IF NOT RunTrigger THEN EXIT; " condition present in your event function? I think it might be causing the issue.

    I resolved my problem by checking the conditions and debugging the code, I found some code which was preventing the system to enter into the event function.

    Please try compiling all objects with validation.
    Thanks,
    Ishwar Sharma

    My Blogs: Dynamics Community Blog | Blogspot
    Connect: Google + | Twitter
  • marvaxmarvax Member Posts: 14
    Hi ishwarsharma016
    I have same problem with the code if not runtrigger.... and without the code if not ..... because i have put a breakpoint before the if not runtrigger and debugger don't stop :(
    I don't understand your answer :
    "
    I resolved my problem by checking the conditions and debugging the code, I found some code which was preventing the system to enter into the event function.
    "
    Which code have you found that prevent the system to enter into the event function?


    Thanks a lot
  • marvaxmarvax Member Posts: 14
    @ishwarsharma016
    Another thing : why nav execute event every time i recompile object.
    So NAV execute event randomly, and when nav don't execute event, just recompile codeunit with event and nav execute again event.
  • mohana_cse06mohana_cse06 Member Posts: 5,503
    there must be something wrong with environment or setup or whatever.
    I have created lot of code with events and extensions but never faced such issue.
  • marvaxmarvax Member Posts: 14
    @mohana_cse06 thanks for your answer. Do you work in Cloud environnement?
  • EvREvR Member Posts: 178
    We've been subscribing to the OnDatabase* events in CU1. It has never failed us so far.
  • ishwarsharma016ishwarsharma016 Member Posts: 50
    @marvax This code I am talking about was a custom publisher and custom subscriber.
    Thanks,
    Ishwar Sharma

    My Blogs: Dynamics Community Blog | Blogspot
    Connect: Google + | Twitter
  • KishormKishorm Member Posts: 921
    @ishwarsharma016 Can you describe the problem you had and your solution a bit more. From your 2nd post above it sounds like this was more of a coding issue than an actual bug in the client. Please don't take this the wrong way - I would just like to know if this is/was actually a bug in the client - I'd feel a lot happier if it was a coding issue (we all do it ;) ) since events are becoming so critical to development now

    @marvax Have you tried restarting the NST service - does this help? BTW, If this is a reproducible issue then you should really report to Microsoft - they may be able to help identify the issue or fix it in a later release if it is a bug in the client.
  • Lars_WestmanLars_Westman Member Posts: 116
    Subscriptions are indeed in executed in random order. There's no way to know in advance which subscriber will execute first if there's more than on subscriber on an event.
  • mohana_cse06mohana_cse06 Member Posts: 5,503
    it doesn't matter whether it is cloud or onpremise version. it works everywhere for everyone..
  • marvaxmarvax Member Posts: 14
    @mohana_cse06 our setup is a standard setup, all parameters are standard. We just work with office 365 authentication.
  • marvaxmarvax Member Posts: 14
    @Kishorm yes we have restarted NFS Service. Just remember my post : i say that i put a breakpoint in standard event (@ishwarsharma016 ) onafterinsert and nav don't stop on my breakpoint, so nav don't execute event . And when i recompile object : nav stop on my breakpoint and so execute correct code (@BlackTiger my code is correct)
  • EvREvR Member Posts: 178
    BlackTiger wrote: »
    There is no such thing as "random" in computer world. 99% of "random" is developer's fault. 1% is developer's fault too. Check your code. Then ask MS to check their code.

    Well there is such a thing. If the event subscribers are triggered asynchronous, depending on the state of the CPU, certain threads can get priority over others, so yes it is possible that the order in which events are triggered can appear random.
  • Erik_LaarmanErik_Laarman Member Posts: 4
    Same here... onafterdelete trigger sometime executed, sometimes not executed. Could this be caused by forgetting to restart the NAV service after importing new objects?
Sign In or Register to comment.