Importing
and Adding all the TransferLines for a TransferOrder at a time using a
Button, From a “.CSV” file
The requirement is that, instead of adding each
TransferLine separately , add all the TransferLines from a .CSV,
at time by clicking a button in TransferLine form for Single
TransferOrder
Step1:
a)*Go
to USMF--Inventory Management—Periodic—TranferOrders, open
the form
*check
what are the tables and form used for the the TransferOrder and Line
1.InventTransferOrderTable
2.InventTransferLine
3.InventTransferOrder----form
b)
[Create a CSV file with some dummy data as same as in the Line form (or) refer axbeginners.blogspot.in ]
Step2
*Add a button(Excel) in the action pane of the
Line form
*Under clicked() method of this button , we
have to write the logic, to import and add all the
Lines at a time
[when ever you are clicking the button ,it
should open a dialog form where we can mention
the path of the Csv file]
*write the code under button
void
clicked()
{
Dialog
dialog;
DialogField
dialogFileName;
SysOperationProgress
simpleProgress;
Filename
filename;
FileIOPermission
permission;
TextIO
textIO;
#define.ShipDate("1/1/2014")
#define.ReceiveDate("1/1/2014")
#define.Site("1")
#define.Warehouse("11")
InventTransferTable
inventTransferTable1;
InventTransferLine
inventTransferLine1;
InventDim
inventDim1;
str
s11;
int
i;
Container
c1;
CompanyInfo
companyInfoLoc = CompanyInfo::find();
Container
filterCriteria;
#File
#avifiles
;
super();
dialog
= new
Dialog("Importing
Text File");
dialogFileName
= dialog.addField(extendedTypeStr(Filenameopen),
"File
Name");
filterCriteria
= ['*.txt'];
filterCriteria
= dialog.filenameLookupFilter(filterCriteria);
dialog.run();
if
(dialog.run())
filename
= dialogFileName.value();
if(!filename)
{
info("Filename
must be filled");
}
permission
= new
fileIOpermission(filename,#io_read);
permission.assert();
textIO
= new
TextIO(filename,#io_read);
textIO.inFieldDelimiter(',');///Change
the Delimeter if it is , or ; etc
simpleProgress
= SysOperationProgress::newGeneral(#aviUpdate, 'Importing
sales data',100);
if(textIO)
{
while(textIO.status()
== IO_Status::Ok)
{
c1
= textIO.read();
s11
= conpeek(c1,1);
if(strlen(s11)
> 1)
{
try
{
ttsbegin;
if
(inventTransferTable.validateWrite())
{
//
to gnererate all the Order lines
inventDim.clear();
inventDim.InventSiteId
= "1";
inventDim.InventLocationId
= "12";
inventDim.InventLocationId
= Conpeek(c1,2);
inventTransferLine.clear();
inventTransferLine.initValue();
inventTransferLine.ItemId
= Conpeek(c1,1);
inventTransferLine.InventDimId
= InventDim::findOrCreate(inventDim).inventDimId;
inventTransferLine.QtyTransfer
= Conpeek(c1,3);
inventTransferLine.initFromInventTableModule(InventTableModule::find
(inventTransferLine.ItemId,ModuleInventPurchSales::Invent));
inventTransferLine.QtyRemainReceive
= inventTransferLine.QtyTransfer;
inventTransferLine.QtyRemainShip
= inventTransferLine.QtyTransfer;
inventTransferLine.ShipDate
= str2Date(#ShipDate,
213);
inventTransferLine.ReceiveDate
= str2Date(#ReceiveDate,
213);
inventTransferLine.initFromInventTransferTable(inventTransferTable,
false);
inventTransferLine.LineNum
= InventTransferLine::lastLineNum
(inventTransferLine.TransferId)
+ 1.0;
if
(inventTransferLine.validateWrite())
{
inventTransferLine.insert();
}
else
throw
error("Order
line");
}
ttscommit;
}
catch
{
error("Error!");
return;
}
info("Done!");
}
i++;
simpleProgress.incCount();
simpleprogress.setText(strfmt("Lines
imported: %1",
i));
sleep(10);
}
}
}
Step4
Again
go to
USMF--Inventory Management—Periodic—TranferOrders, open the
form. then create a new Transfer order and click the button
[Choose
the path of the CSV file in dialodg form and give OK [Create a CSV
file with some dummy data as same as in the Line form ]
No comments:
Post a Comment