Thursday, March 1, 2012

File import and Create a PO with Packing slip and move file

class ImportFiles
{
Filename itemFileName;
Filename Filename;
Filename sourcefile;


}
......................
void First()
{

int handle;
container con;
filename file;
atnaFiletype type;
Filename path;
Filename destfile;

int i;
;

i =0;

if(WinApi::folderExists(InventParameters::find().to))
{
[handle,fileName] = WinApi::findFirstFile(InventParameters::find().from+"\\"+ "*.*");//"."+InventParameters::find().atnaFiletype);
while(fileName!= "")
{
//currentfileName = fileName;

if(filename != "." && filename != "..")
{

info(filename);

con = Docu::splitFilename(filename);
type = conpeek(con,2);
file = conpeek(con,1);
path = InventParameters::find().from+"\\";

sourcefile =path+file+"."+type;
if(InventParameters::find().atnaFiletype == type)
{
this.newimportdatainpurchline();

type = conpeek(con,2);
file = conpeek(con,1);
path = InventParameters::find().to+"\\";

destfile = path+file+"."+type;

if(winapi::fileExists(destfile))
{
info(strfmt("file already present so its deleted -> %1", filename));
winapi::deleteFile(destfile);
}

movethefileanddelete(sourcefile,destfile);
}
else
{
info(strfmt("The file Type in folder is %1 and File type defined in parameter's is %2 ",type,InventParameters::find().atnaFiletype));
}
}
filename = WinApi::findNextFile(handle);
i++;



}
}

}
..................................
public void newimportdatainpurchline()
{
CommaIo file = new CommaIo(sourcefile,'r');
container con;
Purchline Purchline;
PurchTable purchTable;
PurchFormLetter PurchFormLetter;
numberSeq numberSeq;
int x,y;
;
file.inFieldDelimiter(',');


if (file)
{
info(strfmt("File:%1",sourcefile));
//FOR INSERTING INTO HEADER


ttsbegin;
numberSeq = NumberSeq::newGetNumFromCode(PurchParameters::numRefPurchId().NumberSequence);
purchTable.PurchId = numberSeq.num();
purchTable.initValue();

PurchTable.initValue();
purchtable.OrderAccount = "3003";
purchtable.InvoiceAccount ="3003";
purchtable.CurrencyCode ="INR";
PurchTable.initFromVendTable();
purchtable.PurchaseType = PurchaseType::Purch;
purchTable.PurchStatus = PurchStatus::Backorder;
purchtable.insert();
ttscommit;

while(file.status() == IO_Status::Ok)
{
con = file.read();
if (con)
{
// FOR INSERTING INTO LINES
Purchline.clear();
Purchline.PurchId = purchTable.PurchId;


Purchline.InventDimId = "Ax#99";

Purchline.Shift = conpeek(con,2);
Purchline.CenterCode = conpeek(con,3);
Purchline.Producercode = conpeek(con,4);
Purchline.Sampleno = conpeek(con,5);
Purchline.Atna_Milktype = conpeek(con,6);

if(Purchline.Atna_Milktype == Atna_MilkType::C)
{
Purchline.ItemId = InventParameters::findRecod_C().Atna_Milkymistitemcode;

}
else
if(Purchline.Atna_Milktype == Atna_MilkType::B)
{
Purchline.ItemId = InventParameters::findRecod_B().Atna_Milkymistitemcode;
}

Purchline.Qty_Ltr = conpeek(con,7);
Purchline.Temperature = conpeek(con,8);
Purchline.Atna_Fat = conpeek(con,9);
Purchline.Atna_LR = conpeek(con,10);
Purchline.Atna_Snf = conpeek(con,11);

purchLine.createLine(NoYes::Yes, // Validate
NoYes::Yes, // initFromSalesTable
NoYes::Yes, // initFromInventTable
NoYes::Yes, // calcInventQty
NoYes::Yes, // searchMarkup
NoYes::Yes);
}
}
//FOR POSTING THE PO

// Purchformletter = Purchformletter::construct(DocumentStatus::PurchaseOrder);
// Purchformletter.update(PurchTable,
// "Pac_"+purchTable.PurchId,
// systemdateget());


// //FOR POSTING THE PS

Purchformletter = Purchformletter::construct(DocumentStatus::PackingSlip);
Purchformletter.update(PurchTable,
"Pac_"+purchTable.PurchId,
systemdateget());








}

}
.........................................
static void main(Args _args)
{
ImportFiles impfle;
;
impfle = new ImportFiles();

impfle.First();

}
...........................GLOBAL....................

static void movethefileanddelete(filename _srcFile,filename _destFile)
{
System.Exception ex;
Set permSet = new Set(Types::Class);
str errorMsg;
;
try
{
permSet.add(new FileIOPermission(_srcFile, 'rw'));
permSet.add(new InteropPermission(InteropKind::ClrInterop));
permSet.add(new FileIOPermission(_destFile, 'rw'));
CodeAccessPermission::assertMultiple(permSet);
System.IO.File::Move(strfmt(@"%1",_srcFile), strfmt(@"%1",_destFile));
{
info(_destFile);
info("file moved");
}
CodeAccessPermission::revertAssert();
}
catch (Exception::CLRError)
{
ex = ClrInterop::getLastException();
if (ex != null)
{
ex = ex.get_InnerException();
if (ex != null)
{
error(ex.ToString());
}
}
}
}

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...