Working with AX 2012 you soon learn that CIL code can cause problems and searching the web you find out you might need to clear the CIL folder. The problem is there are a few different advises out there and most of them miss out on a vital step.
Here is how to do it the right way, clearing the CIL cache and regenerating it:
- Make sure you have no compilation errors in code
- Stop ALL AOS services for the AX instance
- In SQL Server Management Studio truncate the SYSXPPASSEMBLY table in the modelstore database
- Go to the XppIL folder for the instance …\Server\INSTANCE NAME\bin\XppIL for each AOS services
- Make a backup of the folder content, in case you want to play it safe
- Delete all content of the folder for each AOS services
- Start ONE AOS service, preferably what is considered to be the primary AOS, for the AX instance
- Open AX and start Generate Full CIL, from menu Build\Generate full CIL or corresponding button in ribbon, in workspace
- When it is done, you can start any other AOS services, one at a time
There are two types of caches for a user. Values and settings are saved in SysLastValue table. Code and labels are saved in auc and kti files in the %USERPROFILE%\AppData\Local\ folder which can be located on each server or in a server share if a server farm is used with roaming.
If you want to make sure there is no old cache disturbing when code is upgraded you can clear these two. If the users have made a lot of changes in forms they might get a bit upset losing it all but sometimes it really is a must.
By using PowerShell you could script to clear all of this. While shipping code and services are down, send a SQL command Delete from SysLastValue and then for each user, iterating the user table in AX, go to the %USERPROFILE%\AppData\Local\ folder, or just C:\Users\CurrentUser\AppData\Local folder if you find it easier and know that is the path used, and delete all ax*.auc and ax*.kti files.
Another short post about this http://axninja.blogspot.se/2014/04/ax-user-caches.html
A post showing how to batch the clearing of file caches by using bat files http://blog.bhsolutions.com/index.php/2014/05/dynamics-ax-2012-spring-cleaning-app-data/. However this one, as it is written in the post, just works per user so each user would have to have the bat scheduled.
How do you find the way back to which project journal lines upon which a project invoice is based?
ProjInvoiceTable only holds the Invoice Id while ProjInvoiceJour table holds the Invoice id, Proposal id as well as Project Id. These fields can also be found in ProjProposalJour table, so you may just as well use that, unless there is some specific value which you need from there. If you want to check if the proposal has been invoiced, you can check the LineProperty value.
From there on you either need to know which type of project journal that was used to post the cost or check them all. The tables used are ProjProposalCost, ProjProposalEmpl, ProjProposalItem, ProjProposalOnAcc, ProjProposalRevenue and they all have a corresponding Detail table.
The last step is the ProjJournalTrans table. For all the other tables you can find the relations on the tables to see which fields are used to link records. This one can not be found on the Relations node. The field TransId holds the relation between the ProjProposal… tables and the ProjJournalTrans table.