Options

[SOLVED] Event listener and CHANGECOMPANY

ReinhardReinhard Member Posts: 249
edited 2017-07-01 in NAV Three Tier
When you run code in company "A" like:
Rec.CHANGECOMPANY('B');
Rec.INSERT(TRUE);

The onInsert trigger runs in company "A"
So we know that for CHANGECOMPANY we should always do INSERT(FALSE)

I was curious what would happen with Events.

If I move my code from the onInsert to an onAfterInsert listener instead.

Turns out that the event is picked up, and runs in the original company, similar to the old triggers. But there's no explicit way to opt out of the listener firing.
Another good reason to put
IF NOT RunTrigger THEN EXIT;
in the beginning of many event listeners.

Anyways... just sharing...

Best Answer

  • Options
    bbrownbbrown Member Posts: 3,268
    Answer ✓
    BTW - Same issues occur with field OnValidate that reference other tables. Those references will be to the original company.
    There are no bugs - only undocumented features.

Answers

  • Options
    bbrownbbrown Member Posts: 3,268
    Or avoid the use of CHANGECOMPANY on tables with trigger or event code.
    There are no bugs - only undocumented features.
  • Options
    bbrownbbrown Member Posts: 3,268
    Answer ✓
    BTW - Same issues occur with field OnValidate that reference other tables. Those references will be to the original company.
    There are no bugs - only undocumented features.
Sign In or Register to comment.