About Me

Saturday, December 24, 2011

Import sales orders from master and details text files

The are many code snippets which you can find easily over the internet to import sales orders from a text file or from excel. The purpose of this post is to share my experience of uploading data into sales order form from two different text files.

void ImportSalesOrders()

{

Container con;

CustTable custTable;

SalesTable salesTable;

SalesLine salesLine;

Headers headers;

Stock details;

num newSalesId;

Description custDescription;

InventTable inventTable;

InventDim inventDim;

InventSiteId inventSiteId;

InventLocationId inventLocationId;

CustAccount custAccount;

real itemPrice;

ItemId itemId;

InventDim frominventDim,ToinventDim;

int x,y;

NumberSeq num;

SysOperationProgress progressbar = new SysOperationProgress();

int i;

;

progressbar.setCaption('Importing Journals');

progressbar.setAnimation(filenameHeader);

progressbar.setTotal(30000);

for (i = 1; i <= 30000; i++)

{

progressbar.setText(strfmt("@SYS105740", i));

progressbar.setCount(i, 1);

}

this.importData();

ttsbegin;

while select headers

{

SalesTable = SalesTable::findDocumentNumber(headers.DocumentNumber);

if(!SalesTable)

{

//create sales table

salesTable.initValue();

num = NumberSeq::newGetNum(SalesParameters::numRefSalesId());

newSalesId = num.num();

if (salesTable::exist(newSalesId))

{

num.abort();

throw error("@SYS23020");

}

salesTable.SalesId = newSalesId;

num.used();

if(custDescription != "")

{

salesTable.SalesName = custDescription;

}

custAccount = headers.CustAccount;

//fetch the customer details from cust table using account no selected from drop-down list