Tuesday 28 July 2015

Upload .csv file through job in ax 2012

Upload .csv file through job in ax 2012

static void Atul_test(Args _args)
{
    CommaIO                     csvFile;
    container                   readCon, ledgerDimension;
    counter                     icount,inserted;
    Dialog                      dialog;
    DialogField                 dfFileName, dlgJournalNum, JVNumber;
    FileName                    fileName;
    Struct                              struct;
    str 50  jid;
    ;
     inserted =0;
    #File
    dialog      = new Dialog("Pick the file");
   dfFileName  = dialog.addField(extendedTypeStr(FilenameOpen));
    dialog.filenameLookupFilter(["All files", #AllFiles]);      
    if(dialog.run())
    {
            fileName = dfFileName.value();
    }
   
    csvFile  = new CommaIO(fileName, 'r');
   
    if(csvFile)
    {  
        ttsBegin;
        while (csvFile.status() == IO_Status::OK)
        {
          readCon  = csvFile.read();
          if(readCon)
            {

            // write your code, which data you want to upload from csv file.  
               
               
              icount++;
              inserted++;
            }  
        }  
         ttsCommit;
    }
                info(strfmt("%1 records Updated out of %2",inserted,icount));
}


Thank you!

Wednesday 15 July 2015

Fetch Financial Dimension and dimension description through code in Ax 2012

I am writing this post to demonstrate to find Fetch Financial Dimension through code in Ax 2012.


// declare buffer

SalesOrderDataTmp                         _salesOrderDataTmp;
DimensionAttributeValueSet           dimAttrValueSet;    
DimensionAttributeValueSetItem   dimAttrValueSetItem;   
 DimensionAttributeValue               dimAttrValue;    
DimensionAttribute                         dimAttr;


// get financial dimension            dimAttrValueSet = DimensionAttributeValueSet::find(salesLine.DefaultDimension);

// Find all of the 'value set items' linked against the 'value set'            
financialDim="";            
while select DimensionAttributeValue from dimAttrValueSetItem                
where   dimAttrValueSetItem.DimensionAttributeValueSet   == dimAttrValueSet.RecId            
{                
dimAttrValue        = DimensionAttributeValue::find(dimAttrValueSetItem.DimensionAttributeValue);
// Find the underlying attribute.                dimAttr             = DimensionAttribute::find(dimAttrValue.DimensionAttribute);
//info(dimAttr.Name + ' - ' + dimAttrValue.getValue());
if (dimAttr.Name == 'R1_LegalEntity')
{
// *******************************
// dimAttrValue.getName() fetches the description of the dimension
god_salesOrderDataTmp.Dimesnions1   = dimAttrValue.getName();
                        
// *******************************
// dimAttrValue.getValue() fetches the description of the dimension
god_salesOrderDataTmp.Dimesnions1   = dimAttrValue.getValue();
}                
if (dimAttr.Name == 'R2_Department')                    
god_salesOrderDataTmp.Dimension2   = dimAttrValue.getName(); // .getValue();                
if (dimAttr.Name == 'R3_Region')                    
god_salesOrderDataTmp.Dimension3   = dimAttrValue.getName();                
if (dimAttr.Name == 'R4_CostCenter')                    
god_salesOrderDataTmp.Dimension4   = dimAttrValue.getName();               
 if (dimAttr.Name == 'R5_ProductCatagories')                    
god_salesOrderDataTmp.Dimension5   = dimAttrValue.getName();                
if (dimAttr.Name == 'R6_SalesType')                    
god_salesOrderDataTmp.Dimension6   = dimAttrValue.getName();

financialDim += dimAttrValue.getName() +",";            

}
god_salesOrderDataTmp.insert();


Import General journal from excel in D365 F&O

 Hi Guys, Import General journal from excel in D365 F&O Code:  using System.IO; using OfficeOpenXml; using OfficeOpenXml.ExcelPackage; u...