martedì 19 maggio 2026

D365FFO, AX2012 - Contare i record su una tabella

Con questo semplice job è possibile contare il numero di record su una tabella passata come parametro. Il conteggio avviene cross company oppure su determinate company selezionate. L'operazione può essere utile per informazini statistiche. 

In ax 2012 l'informazione è già presente cliccando quì:

 static void LILRecordTableCount(Args _args)  
 {  
   Common    common;  
   DictTable  dt;  
   DataArea   dataArea;  
   int64    totalCount;  
   int64    companyCount;  
   TableName  _tableName = "CustTable";  
   
   
   //metodo 1: usare crossCompany, utile per un conteggio secco  
   dt = new DictTable(tableName2id(_tableName));  
   
   common = dt.makeRecord();  
   
   select crossCompany count(RecId) from common;  
   
   info(strFmt("Totale record su tutte le company: %1",common.recId));  
   
   //metodo 2: usare changeCompany, utile per escludere / includere company nel conteggio  
   if(dt.dataPrCompany())  
   {  
     while select dataArea  
       where dataArea.id != "DAT"  
     {  
       common = null;  
   
       changeCompany(dataArea.Id)  
       {  
         common = dt.makeRecord();  
       
         select count(RecId) from common;  
         companyCount = common.RecId;  
   
         totalCount += companyCount;  
   
         info(strFmt("Company %1: %2 record", dataArea.Id, companyCount));  
       }  
     }  
   }  
   else  
   {  
     common = dt.makeRecord();  
       
     select count(RecId) from common;  
     
     companyCount = common.RecId;  
   
     totalCount = companyCount;  
   }  
   
   info(strFmt("Totale record sulle company selezionate: %1", totalCount));  
 }  
   

Nessun commento:

Posta un commento