General AX 2012
Export import of the model
Debug batch
Debug in VS if CIL
Full CIL
tts problem
Create a project with filter
Create a project from a select
CrossCompany
Quick compile by command
Debug batch in VS
Batch
Code Send Mail
DIXF
Source to target with select
Batch dependency
Best practises compilation level 4

Export import of the model
1) In the prod sql :
- BackUp of the 2 databases Ax (Data) + AX_model (Pgm), no need of data base BaseLine

2) In the Test environment :
- Build of all the object, normal build of the object client like forms and class that run on client.
cd "C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin"
axbuild.exe  xppcompileall  /s=01 /altbin="C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin"

- Full CIL (Icon on the Editor), Build of all the object Server + build CIL

If there is no error, we can start the Export.
3) Export on server test
cd "C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities"
axutil exportstore /file:C:\ModelStore\SPECTest20190331.axmodelstore /db:MicrosoftDynamicsAX_model /s:AX-TEST-PROD

4) Import on server prod
- Stop AOS Prod
cd "C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities"
axutil importstore /file:"C:\ModelStore\SPECTTest20190331.axmodelstore" /idconflict:overwrite /verbose
- Start AOS Prod
- Synchronize data dictionnary.


On the Test server : export
---------------------------
cmd as admin

cd C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities

//By default axutil take the data base of the AX config client
axutil exportstore /file:C:\Models\OFOZvX.axmodelstore /db:OF_Oz_Dev_model /s:MAX-AX12D-SQL
axutil exportstore /file:C:\ModelStore\Comp20140907.axmodelstore

//If we want specify a particular database db:DBName
axutil exportstore /file:C:\ModelStore\Comp20140907.axmodelstore /db:DBName /s:AXSQLTest

//with ax shell
example 1 : Export-AXModel –Model "Israel Localization" -File "C:\Models\Ax2012CU7Loc.axmodel" -database "MYDATABASE_model" -server "MYSERVER"
example 2 : Export-AXModelStore -File "C:\ModelStore\Comp20140907.axmodelstore"

On the Prod server : import
---------------------------
axutil importstore  /file:"C:\ModelStore\Comp20140907.axmodelstore" /idconflict:overwrite /verbose

If there is problem of ID conficts, we can use a shema to import
//Initialize-AXModelStore -SchemaName 20140709
//Import-AXModelStore -IdConflict Overwrite -File  –SchemaName  -Server  -Database  -Detail -verbose | Out-File 

1)
Initialize-AXModelStore -SchemaName 20140709
2)
Import-AXModelStore -IdConflict Overwrite -File "C:\ModelStore\Comp20140907.axmodelstore"–SchemaName 20140709 -Server axsql01 -Database comp_model -Detail -verbose | Out-File "c:\ModelStore\20140709.txt"
3)
When done – stop the AOS.
run the following script:
4)
Import-AXModelStore –Apply:20140709 -Server axsql01 -Database PackerProd_model –Details -verbose | Out-File "c:\ModelStore\applylog06072014.txt"
5)
Start AOS.

other cmd :
-----------
AXUTIL delete /model:tmp

Uninstall-AXModel -Model "PSS" -database "AX2012R2Loc" -server "MYSERVER"

//Another example
axutil importstore /file:"E:\Modelstore\MyInstance.axmodelstore" /idconflict:overwrite /db:MyInstance_Test_Model /s:preprod-test

Initialize_AXModelStore -AOSAccount "Contoso\AxAOS" -SchemaName Test -Server AXTest -Database Test1

Initialize-AXModelStore -SchemaName MyInstanceDrop

Import-AXModelStore -IdConflict Overwrite -File "E:\Modelstore\MyInstance.axmodelstore" –SchemaName MyInstanceDrop -Server preprod-test
      -Database MyInstance_TEST_model -Detail -verbose | Out-File "E:\ModelStore\MyInstanceDrop.txt"

Import-AXModelStore –Apply:MyInstanceDrop -Server SQLPRODDB\AX -Database MyInstance_Model –Details -verbose | Out-File "E:\ModelStore\MyInstanceDropApply.txt"

Publish-AXReport –Id SQL0AX –ReportName *
Publish-AXReport –Id SQL1AX –ReportName *

Export-AXModelStore -File "E:\ModelStore\MyInstance.axmodelstore" –Details



Debug batch
1.Open Visual Studio as 'administrator' and attach the debugger to the Ax32Serv.exe process.
2. Note that it may also be necessary to change the ‘Attach to’ selection to ‘Managed (v4.0) code’ and make sure “just my code” is unchecked in VS: tools->options->debugging->General
3.Once done, open up the file you want to debug in Visual Studio. All of the X++ code is compiled into IL and can be found in the following directory after deployment:
 ..\Program Files\Microsoft Dynamics Ax\6.0\Server\AxaptaDev\Bin\XppIL\source\ 
4.Set a breakpoint in the file you opened. 
5.Go to Ax and run the process in batch mode, or execute the service operation. This will end up hitting your breakpoint, provided you set it in the right place.
Example Debug

Debug in VS if CIL
//IF CIL, the breakpoint doen't work in AXAPA, we need to remove CIL to debug in Axepta
CIL
Example Debug
tts problem
If we have a pb with tts, for example a ttscommit was missing, run the job
//I have an unbalanced X++ TTSBegin/TTSCommit pair has been detected .Cause of this include (a) too many/few TTSBegin or TTS Commit . The current TTS level is '1'
//
//To solve this error there is a job which is to be executed when yo get this error.
static void SPLresetTTS(Args _args)
{
    while (appl.ttsLevel() > 0)
    ttsAbort;
}
Full CIL
//Full CIL is usefull if people are working in CIL
If there is several AOS, stop the all AOS and do full cil on only one AOS.
1.Stop all AOS instances
2.Truncate the SYSXPPASSEMBLY table
a.Open SQL Server Management Studio
b.Open the model store database
c.truncate table SYSXPPASSEMBLY
3.Navigate to the "C:\Program Files\Microsoft Dynamics AX\60\Server\[instance-folder]\bin\XppIL" folder in Windows Explorer
a.Make a backup copy of the XppIL folder
b.Delete the contents of the XppIL folder
4.Restart AOS
5.Compile Full CIL
 a.Open a new Development Workspace (Ctrl+Shift+W)
 b.Open Menu “Build->Generate Full CIL”
 c.Confirm the dialog “Would you like to generate CIL from all X++ code?”
6.Restart the other AOS


Create a project with filter
//To a project fill with a filter
Project

Create a project from a select
//To create a project for example that contains an entire layer.
Project

CrossCompany
//In a query : query.allowCrossCompany(true);


Quick compile by command
cd C:\Program Files\Microsoft Dynamics AX\60\Server\MyXXXDev\bin
axbuild.exe  xppcompileall  /s=01 /altbin="C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin" 

Debug batch in VS
Debug

Batch
// If we modify the class and run in batch, we need to do an incremental CIL to take the new version.
// The parameter of the dialog are private for a batch. Ex if recurrency, it will use always the same parameters.
// If the job batch has a recurrency, the job will appears "Waiting". The result is in Batch history.
Debug

Code Send Mail
// To send an email.
// - We need an email template ex : AMRScanner
// - recipient email address
// - here we add the message.
this.SPLSendMail("AMRScanner",
				 SysUserInfo::find(McsParameters::find().AdministratorModeUserID).Email,
				 SPLListWarning);

// 15-10-2015-SBE
public void SPLSendMail(SysEmailId _sysEmailId,
                        str        _recipientEmail,
                        str        _message)
{
    SysEmailTable::sendMail(
    _sysEmailId,
    SysEmailTable::find(_sysEmailId).DefaultLanguage,
    _recipientEmail,
    null,
    '',
    '',
    true,
    curUserId(),
    false,
    _message); // The messge that I had
}

// SysEmailTable : We add a parameter.
server static void sendMail(
    SysEmailId      _emailId,
    LanguageId      _language,
    str             _emailAddr,
    Map             _mappings = null,
    FilenameOpen    _attachmentFilename = '',
    str _xmlData = '',
    boolean _isTraceable = false,
    UserId _userId = '',
    boolean _isWithRetries = false,
    // 15/10/2015-SBE-BEGIN
    str             _SPLmessage = '')   //Add here the message to add to the message
    // 15/10/2015-SBE-END
{
...
        // 15/10/2015-SBE-BEGIN
        if (_SPLmessage)
            messageBody = messageBody + _SPLmessage;
        // 15/10/2015-SBE-END

}

DIXF
// Add fields to the entity
Entity
// Processing group. tab format
Format

// If generate from scratch Yes, seems to be better -> generate entity attribute , CHECKED !!! GOOD !!!
The entity attribute is regenerate from the file !
Entity

// After we do the Generation of the file and click No, in order not to erase the template.
Gen

// This think wasn't checked !!! //============================//
// When we add a field to our entity, we need to regenerate the processing group.
// If we do regenerate from scratch we loose all the fields ordered in the attribute XML.
// So it is a good thing to generate not from scratch but from the file, and before 
// we added to the file the field that we want to add to the entity.
Format

Source to target with select
//If there were an error in the batch or in the process we can run again and correct 
//manually and select the line we want to correct.
Entity

Batch dependency
//To start a task after another task
Entity

Best practises compilation level 4
//Best practises
BP
BP