... because it was designed this way. The root node of the context is company, representing approx. the same as a company code in SAP (for instance). Transactions outside a company are possible, but more like an afterthought than by design. The context of your transactions (and for all variables within) is set by opening up a session in the specified company. Therefore, all validates and views are in this context. When you do a changecompany() on a table, the context for the TableData object changes, but not for the variables inside the record - meaning all validates work, but refer to the original session context.
In NAV2013 you can start separate background sessions with an entry point (codeunit) and a context (company). I think it will be a big improvement for cross-company transactions, but wouldn't solve the functionality problem many actual NAV users have. They have grown over time and are larger structures now, with several companies (split for legal or technical reasons). This brings master data management issues, and intercompany transactions.
You basically have to take the code within the OnValidate function into what ever code you have written and mirror that code with whatever variables you need and call the CHANGECOMPANY on all those record variables as well.
I have been frustrated by this for years and am looking forward to 2013, for at least some ability to do this.
The change in 2013 isn't in CHANGECOMPANY, but you can actually program C/AL to start a new session in another company, which is actually much better. You can just spin off another session and tell that session what to do, and you can continue on in your own session, very powerful stuff. Might be a good idea for a blog
Comments
... because it was designed this way. The root node of the context is company, representing approx. the same as a company code in SAP (for instance). Transactions outside a company are possible, but more like an afterthought than by design. The context of your transactions (and for all variables within) is set by opening up a session in the specified company. Therefore, all validates and views are in this context. When you do a changecompany() on a table, the context for the TableData object changes, but not for the variables inside the record - meaning all validates work, but refer to the original session context.
In NAV2013 you can start separate background sessions with an entry point (codeunit) and a context (company). I think it will be a big improvement for cross-company transactions, but wouldn't solve the functionality problem many actual NAV users have. They have grown over time and are larger structures now, with several companies (split for legal or technical reasons). This brings master data management issues, and intercompany transactions.
HTH.
with best regards
Jens
I have been frustrated by this for years and am looking forward to 2013, for at least some ability to do this.
KCP Consultores
RIS Plus, LLC