Field Rename will break Event Triggers

Events are well known in the NAV world today. Everybody is using this very nice feature. Not!?
No more table modifications for validations or extra features when inserting records. Only but advantages from my opinion. But recently I ran into an issue.

I have created a new table with some fields.
Then I created a hook codeunit with 2 functions based on the “OnAfterValidateEvent” trigger.
Nothing special.

After everything was tested, the consultant or customer asked me to change the name of some fields. Not just the captions but also the name.
So as ask, I did the changes and compiled everything without an error. Where the fields were used on pages or in CAL everything was updated with the new field name. And it seems that it would work.

But after testing the solution again we ran into some issues. The validations of the fields were gone and no triggers were fired.
And after some investigation I found the problem in the “Event Subscription” page.

Continue reading  

“OnAfterObjectsChanged” Event

I think the following scenario will sounds familiar to every developer.

You develop a nice new feature with a couple of tables, pages and codeunits. These new objects needs to be imported in the production environment.

You make a fob file of all your objects or create deltas, import it in the development environment and compiles the objects. And maybe you need to restore the NST, but this is questioned many times. Some are saying this is mandatory but I doubt it.

Before your solution will work, you need to do some setup in every company by opening the pages and provide the right parameters. A very time consuming (aka monkey task) to do and if your head isn’t clear you can forget something or make mistakes.

Would it be nice if the system itself will know when there are objects imported and auto configure your solution? That the system will raise an “OnAfterObjectsChanged” event the first time you open a client after you imported you objects.

That is what I’ve created and I will share it with you in a moment.

The first part is to determine if there are objects imported to the system. As you properly know these are created and updated in the system table “Object”.
Now I need to know when this table is changed from within NAV itself.

First, I thought to use “OnAfterInsert, OnAfterModify or OnAfterDelete¬†Events” on this table, but these will not be raised from within the development environment when you import objects.

But then I come up with the following idea.

As you might know there is a field called “Timestamp” in every NAV table. This is maintained by SQL on every insert and update.
So, if I make a sum of all the timestamps in the “Object” table and compare it with a previous saved value, I know that something has changed and even that there are records deleted!

To get the sum of the timestamps, I used the following SQL statement and executed from within NAV itself.

Continue reading  

Vote: Rename Event Parameters

This week I started to transform some OnAfter and OnBefore Hooks on tables to Events.
When performing these manuel steps I first though about Upgradeability. Every modification must be upgraded smoothly without any manual handling afterwards.
So what will the result be if I upgrade a customer with the Hook triggers? I tested with a simple example. Continue reading  

A Special Way of Debugging

Every developer needs to debug every now and then.
But it becomes a challenge when you didn’t wrote every line of code.

Maybe an addon will case the problem.
Default NAV or a CU update can also be the reason.
Or the combination of these.

So where do you begin? First you start debugging and break just before you press the function that causes the problem.
Then you follow every line of code in the debugger. Jump from one codeunit to another. Very time consuming. Continue reading  

OnAfterValidate Event firing is fixed in NAV2016 CU5!!!

As I have warned you on my previous post, there was an issue where the OnAfterValidate Event wasn’t fired as expected.

Yesterday Microsoft has released CU5 of NAV2016 with a platform hotfix special for this behavior as you can see. Continue reading