How to import CSV file with Progress bar indication in Ax 2012 & Ax 2009

static void ImportCSVwithProgresBar(Args _args)

{

Filename                    fileName;

container                   files,inRecord,toTRec;

CommaIO                     commaIO;

Dialog                      _dialog;

DialogField                 _dialogFieldFileName;

counter                     counter = 0;

counter                     ErrCounter = 0;

counter                     progressCounter = 0;

SysOperationProgress        progress = new SysOperationProgress();

 

InventTable                 inventTable;

ItemID                      searchItem;

int                         totRows;

 

TextBuffer tb;

;

 

_dialog              = new Dialog(‘ImportCSV’);

_dialogFieldFileName = _dialog.addField(ExtendedTypeStr(FileNameOpen), ‘@SYS53125’, ‘@JKI58’);

_dialogFieldFileName.lookupButton(2);

 

if (_dialog.run())

{

Setprefix(‘@JKI57’);

fileName = _dialogFieldFileName.value();

if(!fileName)

{

info(strfmt(‘@SYS18624’));

return;

}

 

tb = new TextBuffer();

tb.fromFile(fileName);

totRows = tb.numLines();

 

commaIO = new CommaIO(fileName, ‘@SYS76352’);

inRecord = commaIO.read();

progress.setCaption(“@SYS4128”);

#AviFiles

progress.setAnimation(#AviUpdate);

inRecord = commaIO.read();

 

progress.setTotal(totRows);

//progress.setText(strfmt(“Updating Item”, searchItem));

 

ttsbegin;

while (!commaIO.status())

{

searchItem = (conPeek(inRecord, 1));

SetPrefix (strfmt(‘@JKI32’, (progressCounter+1), searchItem));

 

select firstonly forupdate inventTable where inventTable.ItemId == searchItem;

if (inventTable)

{

 

if (InventTable.DimGroupId != “@JKI59” && InventTable.DimGroupId != “@JKI60”)

{

inRecord = commaIO.read();

warning(strfmt(“@JKI61”, InventTable.DimGroupId));

continue;

}

 

inventTable.PdsShelfLife  = str2num(conPeek(inRecord, 2));

inventTable.PdsShelfAdvice = str2num(conPeek(inRecord, 3));

inventTable.PdsBestBefore = str2num(conPeek(inRecord, 4));

 

if (inventTable.validateWrite())

{

counter++;

//inventTable.update();

info(strfmt(“@JKI62”, SearchItem));

}

else

{

ErrCounter++;

error(strfmt(“@JKI63”, progressCounter));

}

}

else

{

warning(strfmt(“@JKI64”, SearchItem));

}

inRecord = commaIO.read();

progressCounter++;

progress.setText(strfmt(“Updating Item %1%”, (progressCounter/totRows)*100));

progress.incCount();

}

 

if (!ErrCounter)

{

ttsCommit;

info(strfmt(‘@JKI66’, counter));

}

else

{

ttsabort;

error(‘@JKI47’);

info(strfmt(‘@JKI67’, ErrCounter));

}

info(strfmt(‘@JKI65’, progressCounter));

}

}

 

Advertisements

Ax 2012 Arrays

An array is a collection of variables that are all of the same type. The elements of an array are accessed with simple integer indexes.

There are three kinds of arrays:

  • Dynamic
  • Fixed-length
  • Partly on disk

X++ only supports one-dimensional arrays. It is possible, however, to mimic the behavior of multiple array indices.

Example JOB:

static void ArrayTypes(Args _args)
{
Name DynamicArray[];
Name FixedArray[4];
//Name PartllyOnDiskArray[,8]; // if you use like this then it is Dynamic array of Name only 8 in memory
Name PartllyOnDiskArray[16,8];// if you use like this then it is Fixed length array of Name wit 16 elements and 8 in memory

int i,j;
 CustTable custTable;
 ;

while select AccountNum from custTable
where custTable.CustGroup==”30″
{
i++;
DynamicArray[i] = custTable.AccountNum;

if(i<=4)
FixedArray[i] = custTable.AccountNum;

PartllyOnDiskArray[i] = custTable.AccountNum;

}
setPrefix(“Array Types”);
setPrefix(“FixedArray”);
for (j=1;j<=dimOf(FixedArray);j++)
{
info(strFmt(“Fixed Array – %1”,FixedArray[j]));
}
setPrefix(“Dynamic Array”);
for (j=1;j<=dimOf(DynamicArray);j++)
{
info(strFmt(“Dynamic Array – %1”,DynamicArray[j]));
}
setPrefix(“PartlyOnDisk Array Memory value”);
for (j=1;j<=dimOf(PartllyOnDiskArray);j++)
{
info(strFmt(“PartlyOnDisk Array – %1”,PartllyOnDiskArray[j]));
}
setPrefix(“PartlyOnDisk Array fully printed (Disk + Memory)”);
for (j=1;j<=16;j++)
{
info(strFmt(“PartlyOnDisk Array – %1”,PartllyOnDiskArray[j]));
}

}