X++ Code
|
Almost regularly I receive emails requesting for import/export jobs. Here are couple of simple examples. If you have any query, please do not hesitate to contact me.. 1) Here is a small job that imports Chart of Accounts into Axapta. Please note that this job is meant more as a starting point for beginners in Axapta. Considering that, I have added some comments across the job.
------------------------------------------------------------------------
static void CoAImport(Args _args)
{
/*
*************************************************************************
Author : Harish Mohanbabu
Purpose : Demonstration for importing CoA into Axapta
*************************************************************************
*/
LedgerTable ldt;
AsciiIO inFile;
Filename filename;
Container line;
Dialog dialog;
DialogField dialogField;
;
/*
Note - In this example, I have used 'Dialog' & DialogField classes
as a tool for me to select the file that has to be imported. If required, you can directly select
the file to be imported. For ex -
filename = 'C:\\
|
2) I wrote this simple job to demonstrate exporting data from Axapta. Also I have mentioned few file operations like copying into clipboard, deletion etc. Please note that I have used CommaIO class here. If required it is
also possible to use class like AsciiIO etc. Here I go ....
static void FileOperations(Args _args)
{
/*
......................................................
Author : Harish Mohanbabu
Purpose : Demonstration for creating a text file and
writing contents into that file
......................................................
*/
CustTable cust;
CommaIO myfile;
TextBuffer tb;
counter recordCount;
int i;
str fileName;
;
fileName = "C:\\Axapta1.txt"; //<- Alternatively 'Dialog' can be used.
//<- Instead of '.Txt', extensions like
//.Doc, .Xls can also be used.
//Creating new file with write access
myfile = new commaIO(fileName,"w");
//Setting up Record delimiter
myfile.outRecordDelimiter("\r\n");
myfile.outFieldDelimiter(",");
while select cust order by accountnum
{
myfile.write(cust.AccountNum, cust.Name);
}
myfile.write('..........................................');
//To find out record count & write the same end of the file
recordcount = new sysdicttable(tablenum(custTable)).recordCount();
myfile.write("Inserted " + int2str(recordcount) + " Records");
//To close this file
myfile = null; //<- Finalize() method is protected. Hence this alternative ...
//To copy contents of this file into clipboard
tb = new TextBuffer();
tb.fromFile(filename);
tb.toClipboard();
tb = null;
//To delete this file
//winapi::deleteFile(fileName);
//Alternatively To move this file
//winapi::moveFile(fileName, newfileName); // <- Declare 'newfileName'
}
|
3) I wrote this simple job to demonstrate connecting to a website from Axapta and downloading a web page into the local hard disk. Here I go ....
static void ReadHTML(Args _args)
{
......................................................
Author : Harish Mohanbabu
Purpose : Demonstration for connecting to a website and
downloading a webpage from there....
......................................................
str page;
str filename;
commaIO myfile;
int handle;
WinInet wi = new WinInet();
;
filename = "C:\\HTMLfile.txt";
myfile = new commaIO(filename,"w");
handle = wi.internetOpenUrl('http://www.harishm.com');
if (handle)
{
page = wi.internetReadFile(handle);
myfile.write(page);
}
wi.internetCloseHandle(handle);
}
|