EXPORT TO CSV DIRECT JOB X++ WITH DATE : VIKAS MEHTA
public static void
export2csvInvJourTrans(InventJournalId _invJournalId)
{
container con, conHeader;
InventJournalTrans invJourTrans;
InventJournalTable invJourTable;
InventDim invDim;
CommaIo io;
Dialog dialog;
DialogField dlgFileName;
Filename csvfileName;
FileIOPermission permission;
int recordCount = 0;
SysOperationProgress exportprogress = new
SysOperationProgress();
#File
#AviFiles
;
try
{
exportprogress.setCaption("Exporting journal lines to CSV
file....");
exportprogress.setAnimation(#AviTransfer);
// Header Column
conHeader =
["JournalId","Date","ItemId","Description","LineNum","Site","Warehouse","Location","SerialNumber","OnHand","Counted","Quantity"];
dialog = new Dialog("Export to
CSV");
dialog.filenameLookupFilter(["Excel
Files","*.csv"]);
dlgFileName =
dialog.addField(extendedTypeStr(FilenameSave),"File Name");
if(dialog.run())
{
csvfileName = dlgFileName.value();
if(csvfileName)
{
permission = new
FileIOPermission(csvfileName,#io_write);
permission.assert();
io = new
CommaIo(csvfileName,#io_write);
io.inFieldDelimiter(',');
if(!io || io.status() !=
IO_Status::Ok)
{
throw error("Error in
opening file!");
}
// Write the header column
io.writeExp(conHeader);
invJourTable =
InventJournalTable::find(_invJournalId);
if(!invJourTable.Posted)
{
recordcount = 1;
while select * from
invJourTrans where invJourTrans.JournalId == _invJournalId
{
// Create rows
invDim = InventDim::find(invJourTrans.InventDimId);
con= [ _invJournalId,
date2str(invJourTrans.TransDate,123,-1,-1,-1,-1,-1),
invJourTrans.ItemId,
invJourTrans.itemName(),
invJourTrans.LineNum,
invDim.InventSiteId,
invDim.InventLocationId,
invDim.wMSLocationId,
invDim.inventSerialId,
num2str(invJourTrans.InventOnHand,1,2,1,0),
num2str(invJourTrans.Counted,1,2,1,0),
num2str(invJourTrans.Qty,1,2,1,0)
];
io.writeExp(con);
recordCount++;
}
}
CodeAccessPermission::revertAssert();
}
else
{
info("Invalid file name
specified!");
}
}
}
catch(Exception::Error)
{
throw error("Erorr in exporting
journal lines.");
}
}
No comments:
Post a Comment