ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Scope Change] Codeunit 11 LogTestField, LogError, LogFieldError

Open StephenNorfolk-DC opened this issue 5 years ago • 5 comments

Codeunit 11 "Gen. Jnl.-Check Line" uses ErrorMessageMgt to build up a list of errors.

We are using OnAfterCheckGenJnlLine to check for additional errors, and we'd like to add to the same error list.

Solution 1: Pass the global var for ErrorMessageMgt to OnAfterCheckGenJnlLine

Solution 2: Make the LogTestField, LogError, and LogFieldError functions global, so they can be called from an event subscriber. Edit: you will need to set IncludeSender to true on the OnAfterCheckGenJnlLine event (having this set on all the other events couldn't hurt)

StephenNorfolk-DC avatar Aug 06 '21 15:08 StephenNorfolk-DC

Good point, I noticed this weeks ago but didn't have time to report it. I think solution 2 is superior, then we needn't rewrite the logic for how to use ErrorMessageMgt. But doesn't that then require adding IncludeSender := true to lots of event publishers, so we can call the newly available sender.Log*() methods?

dzzzb avatar Aug 06 '21 15:08 dzzzb

@db-bc I too think Solution 2 is better, more generalised. They will need to add IncludeSender, so I will edit the original post to include that fact.

To be honest, I think there are hundreds of events in the base app that are worth having IncludeSender enabled for. Since a lot of events are added to get around functionality in standard function calls, it would benefit us extending the Base App to be able to utilise the senders global vars and functions, most of the time. I would almost say IncludeSender should be the default, and explicitly set to false when the sender object needs to be protected.

StephenNorfolk-DC avatar Aug 09 '21 08:08 StephenNorfolk-DC

it would benefit us extending the Base App to be able to utilise the senders global vars and functions, most of the time.

IncludeSender doesn't give access to global variables. There used to be GlobalVarAccess that would allow that, if the subscriber added 'parameters' corresponding to global variables, but it is deprecated and documented as pending removal:

Using GlobalVarAccess will throw a compiler warning, which will become an error in a future release. Instead use the event parameters or mark the page or table variables as protected. For more information, see Protected Variables.

from IntegrationEvent Attribute documentation

and that's good, IMO; global variables are bad enough (if sometimes difficult to avoid in some patterns) within the object in which they're global, without everyone else having free reign to poke around in them in ways the base object can never expect.

dzzzb avatar Aug 09 '21 08:08 dzzzb

Yes you're right. I forgot about that property, and agree that global vars shouldn't be messed with externally.

StephenNorfolk-DC avatar Aug 09 '21 09:08 StephenNorfolk-DC

Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.

JesperSchulz avatar Aug 09 '21 13:08 JesperSchulz