giovedì 16 gennaio 2020

AX 2012 - Job Fieldname print

In this post I'll share a job made in order to print an infolog having all the fields of a table in ax with some useful information like, field name, label, help text, data type.

 static void AGIA_TableFieldNames_2(Args _args)    
 {    
      DictTable dt           = new SysDictTable(77);    
      FieldId _fieldId     = dt.fieldNext(0);    
      DictField                _dictField;    
      Dialog                dialog;    
      DialogField           myDialogField;    
      tablename                id;    
      dialog                     = new dialog();    
      myDialogField           = dialog.addField(extendedTypeStr(tablename), "TableName : ");  
      dialog.run();   
      if(dialog.closedOk())    
      {    
           id = myDialogField.value();    
           dt = new sysdicttable(tableName2id(id));    
           info(strFmt("Field Name; Field Label; Field Type; Field Help; Field Mandatory; Field Lenght"));    
           if(_fieldId)    
           while(_fieldId)    
           {    
                _dictField =dt.fieldObject(_fieldId);   
                if(_dictField)  
                {  
                     if(!_dictField.isSystem())  
                     {  
                          info(strFmt("%1; %2; %3; %4; %5; %6", _dictField.name(),_dictField.label(),_dictField.baseType(),_dictField.help(),_dictField.mandatory(), _dictField.stringLen()));    
                          _fieldId= dt.fieldNext(_fieldId);  
                     }  
                }  
           }    
           else  
           {  
                info(strFmt("Missing table %1", id));  
           }                 
      }    
 }   
Con questo job invece possiamo stampare il contenuto di una tabella (lista dei campi e valore) in maniera dinamica:
 static void LIL_PrintTableValue(Args _args)  
 {  
   DictTable  dt;  
   DictField  dictField;  
   Common   common;  
   Counter   i=0;  
   FieldId   fieldId;  
       
   dt = new DictTable(tableNum(InventSite));  
   
   common = dt.makeRecord();  
    
   while select common  
   {  
       
     fieldId = dt.fieldNext(0);  
       
     while (fieldId)  
     {  
       dictField = dt.fieldObject(fieldId);  
         
       if(dictField.configurationKeyId() != configurationkeynum(SysDeletedObjects60))  
       {  
         info(strFmt("%1 = %2",fieldId2name(dt.id(),dictField.id()),common.(dictField.id())));  
       }  
         
       fieldId = dt.fieldNext(fieldId);  
     }  
       
     info("---------------------");  
   }  
 }  

4 commenti: