[SOLVED] Event listener and CHANGECOMPANY

Reinhard
Member Posts: 249
When you run code in company "A" like:
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
Anyways... just sharing...
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...
0
Best 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.1
Answers
-
Or avoid the use of CHANGECOMPANY on tables with trigger or event code.
There are no bugs - only undocumented features.0 -
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.1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions