mercoledì 26 giugno 2019

AX 2012 - Job per creazione progetto da CSV

In questo post pubblico un job che ho scritto che serve per creare un progetto privato leggendo un csv contenente una lista di tipi e nomi degli elementi dell'AOT

 static void LIL_ProjectElementAdd(Args _args)  
 {  
   TextIo         inFile;  
   container        line;  
   Counter         records;  
   SysOperationProgress  simpleProgress;  
   container        fileContainer;  
   Counter         loopCounter;  
   CustTable        CustTable;  
   InventTable       InventTable;  
   str           filename,  
               properties,  
               objectType,  
               objectName,  
               aotType,aotPath;  
   TreeNode        projectNode,  
               tempNode;  
   ProjectGroupNode    groupNode;  
   boolean         managed;  
   
   #OCCRetryCount  
   #AviFiles  
   #File  
   #aot  
   #DMF  
   
   filename = WinAPI::getOpenFileName(0,  
                 [WinAPI::fileType(#csv),#AllFilesName + #csv],  
                 strFmt(@'C:\users\%1\Desktop',WinApi::getUserName()),  
                 "@SYS53008"  
                 );  
   try  
   {  
     inFile = new TextIo(filename, 'r');  
     inFile.inRecordDelimiter('\n');  
     inFile.inFieldDelimiter(';');  
     while (inFile.status() == IO_Status::OK)  
     {  
       fileContainer += [infile.read()];  
     }  
     inFile = null;  
   }  
   catch  
   {  
     throw error(strFmt("@SYS18678", filename));  
   }  
   
   simpleProgress = SysOperationProgress::newGeneral(#aviUpdate, "Importazione...", conLen(fileContainer));  
   
   records = 0;  
   
   projectNode = SysTreeNode::createProject("MyPrivateProject");  
   
   groupNode  = projectNode.AOTadd("Object");  
   properties = groupNode.AOTgetProperties();  
   
   for (loopCounter = 2; loopCounter <= conLen(fileContainer) - 1 ; loopCounter++)  
   {  
     line = conPeek(fileContainer,loopCounter);  
     objectType = conPeek(line,1);  
     objectName = conPeek(line,2);  
   
     switch(objectType)  
     {  
       case "BaseEnum" :  
         aotType = #BaseEnums;  
         aotPath = #BaseEnumsPath;  
         managed = true;  
         break;  
   
       case "Class" :  
         aotType = #Classes;  
         aotPath = #ClassesPath;  
         managed = true;  
         break;  
   
       case "ExtendedDataType" :  
         aotType = #ExtendedDataTypes;  
         aotPath = #ExtendedDataTypesPath;  
         managed = true;  
         break;  
   
       case "Form" :  
         aotType = "Forms";  
         aotPath = #FormsPath;  
         managed = true;  
         break;  
   
   
       case "Macro" :  
         aotType = "Macros";  
         aotPath = #MacrosPath;  
         managed = true;  
         break;  
   
       case "Menu" :  
         aotType = "Menus";  
         aotPath = #MenusPath;  
         managed = true;  
         break;  
   
   
       case "Table" :  
         aotType = "Tables";  
         aotPath = #TablesPath;  
         managed = true;  
         break;  
   
       case "Map" :  
         aotType = "Maps";  
         aotPath = #TableMapsPath;  
         managed = true;  
         break;  
   
       case "Query" :  
         aotType = #Queries;  
         aotPath = #QueriesPath;  
         managed = true;  
         break;  
   
       case "SecurityDuty" :  
         aotType = "SecDuties";  
         aotPath = #SecDutiesPath;  
         managed = true;  
         break;  
   
       case "SecurityPrivilege" :  
         aotType = "SecPrivileges";  
         aotPath = #SecPrivilegesPath;  
         managed = true;  
         break;  
   
       case "SecurityPrivilege" :  
         aotType = "SecPrivileges";  
         aotPath = #SecPrivilegesPath;  
         managed = true;  
         break;  
   
       case "SecurityProcessCycle" :  
         aotType = "SecProcessCycles";  
         aotPath = #SecProcessCyclesPath;  
         managed = true;  
         break;  
   
       case "SecurityRole" :  
         aotType = "SecRoles";  
         aotPath = #SecRolesPath;  
         managed = true;  
         break;  
   
       case "SSRSReport" :  
         aotType = "SSRSReports";  
         aotPath = #SSRSReportsPath;  
         managed = true;  
         break;  
   
       case "VisualStudioProjectCSharp" :  
         aotType = "VSProjectsCShar";  
         aotPath = #VSProjectsCSharpPath;  
         managed = true;  
         break;  
   
       default:  
         managed = false;  
         warning(strFmt("Unable to add %1, %2",objectType,objectName));  
     }  
   
     if(objectName && managed)  
     {  
       tempNode = TreeNode::findNode(aotPath);  
       groupNode.addNode(tempNode.AOTfindChild(objectName));  
     }  
   }  
   projectNode.AOTsave();  
 }  

L'output sarà il seguente:


martedì 11 giugno 2019

AX 2012 - Job dimensioni finanziarie

In questo post vediamo due job per manipolare le dimensione finanziarie ed assegnare il risultato ad una riga di general journal

Il primo job, data una ledger dimension cambia l'account e valida la nuova dimensione:

 static void LIL_ChangeAccountNum(Args _args)  
 {  
   LedgerJournalTrans           ledgerJournalTrans;  
   DimensionDefault            dimensiondefault;  
   LedgerDimensionAccount         LedgerDimensionAccount, ret;  
   DimensionValidationStatus        status;  
   MainAccountNum             newMainAccountnum = "10505005";  
   
   ledgerJournalTrans = ledgerJournalTrans::findRecId(5644985326, false);  
   
   dimensiondefault = DimensionDefaultingEngine::getDefaultDimension(DimensionDefaultingEngine::getDimensionSourcesForLedgerDimension(ledgerJournalTrans.ledgerdimension));  
   
   LedgerDimensionAccount = AxdDimensionUtil::getLedgerAccountId([newMainAccountnum,newMainAccountnum]);  
     
   ret = DimensionDefaultingService::serviceCreateLedgerDimension(LedgerDimensionAccount,dimensiondefault);  
   
   status = DimensionValidation::validateByTree(ret,today(),true);  
     
   if(status == DimensionValidationStatus::Valid)  
   {  
     ledgerJournalTrans.LedgerDimension = ret;  
   }  
 }  

il secondo crea una ledger dimension contente solamente il bank account num:

 static void LIL_LedgerDimensionWhitAccountOnly(Args _args)  
 {  
   LedgerJournalTrans     ledgerJournalTrans;  
   DimensionDynamicAccount   DimensionDynamicAccount;  
     
   DimensionDynamicAccount = DimensionStorage::getDynamicAccount("BANK001", LedgerJournalACType::Bank);  
     
   ledgerJournalTrans.LedgerDimension = DimensionDynamicAccount;  
 }  


mercoledì 5 giugno 2019

D365 - Script for checking the code executed while inserting data in a table manually

In order to have a quick list of fields inserted in a form we can proceed in the following way.
First insert a record in the table we want to analyse.



At this point access the following button Option --> Record info.


Click on the button Script as reported below.

The following txt document is created, in which the procedures for inserting a row in the table previously filled manually are retrieved.