NAV Design Pattern: Activity Log

The Activity Log pattern tracks execution of activities. This is a Dynamics NAV specific implementation of the generic Audit Log pattern.

Activity Log

In general, integrating with external systems can be very challenging, due to the complexity of the situation – connectivity issues, asynchronous operations, user errors, etc. These challenges require sometimes re-trying several times, polling the external system, re-send/re-get data as all these activities can succeed but can very well fail.

Read more on NAV Design Patterns wiki.

Ciprian Iordache at Microsoft Development Center Copenhagen

Comments (4)

  1. Jeremy Vyska says:

    I’ve written a few error logging solutions within NAV over the years, so this is a great plan. My main challenge with this design pattern: How do you handle ERRORs in NAV with this pattern? Once that hits, you have roll back, and no log data. Almost every time I’ve created a logging system, I ended up having to rely on rapid file writing to prevent the (desired) rollback from also nuking the logging entries.

    1. A deviation of this pattern that also solves the ERROR-problem is to wrap the logging part into a separate codeunit and to call it via STARTSESSION. That results in a separate transaction and won’t be rolled back in case of an error in the outer function. It also helps prevent from these infamous “Page.RunModal() is not allowed in write transactions. “errors.

    2. Ciprian Iordache says:

      Yes, this is the main question I was asked when proposing this pattern.
      Julian’s solution was suggested also by other people but please be aware of the performance impact. STARTSESSION is actually logging in another user so this is quite a resource demanding activity and for just logging a simple message it might be an overkill.
      The solution I chose in one implementation involves some “gymnastics”. Catch all the possible errors (CODEUNIT.RUN or TryFunction) then move the messages to a temporary record, throw error (this will rollback but NOT! the temporary table) then move from temporary to actual table.

  2. Stephan Weidmann says:

    To solve the problem with Logging also in the errorcase:

    I have created a table on sql, and a nav table. the nav table is linked and, important, linked in Transaction = No.
    So an error, occurring in an transaction, is not deleting the logging, Since the logtable is not linked in the transaction.

Skip to main content