Thursday 22 September 2011

Read the same type of file s in single folder

static void loopfilesWinApi(Args _args)
{
    str fileName;
    int handle;
    str format = "*.txt";
    ;

    if(WinApi::folderExists("C:\\Temp\\"))
    {
        [handle,fileName] = WinApi::findFirstFile("C:\\Temp\\" + format);
        while(fileName)
        {
            //currentfileName = fileName;
            info(filename);
            filename = WinApi::findNextFile(handle);
        }
        WinApi::closeHandle(handle);
    }
}

Wednesday 21 September 2011

write data to xml through X++ code


static void Write2ExcelFile(Args _args)
{
InventTable inventTable;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
workbook = workbooks.add();
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
cells.range('A:A').numberFormat('@');
cell = cells.item(1,1);
cell.value("Item");
cell = cells.item(1,2);
cell.value("Name");
row = 1;
while select inventTable
{
row++;
cell = cells.item(row, 1);
cell.value(inventTable.ItemId);
cell = cells.item(row, 2);
cell.value(inventTable.ItemName);
}
application.visible(true);
}

procedure for Parameters form for our own module


1. First, we need to create the number sequence from the number sequence
form found at: Main Menu | Basic | Setup | Number sequences |
Number sequences


As you can see from the previous screenshot, I have created a new number
sequence and called it Rental_1. I have also formatted the number sequence
to have a prefix followed by six digits that can be anything from 1 to 999999.
The General tab in the next figure shows that I have set up this number
sequences as Continuous so that it will increment by one each time a new
record Is created in the RentalTable.


2. When we open the number sequence reference form found at Main Menu
| Basic | Setup | Number sequences | References, we can now link the
reference with the number sequence as shown in the next screenshot

We can also do the same thing from a parameter form, but we first need to
create our parameter table for the CarRental module.


3. We start off by creating a new form and adding the CarRentalParameter as
the data source. We also add the NumberSequenceReference table as a data
source and set the following parameters to it:


4. We now create the design of the form by adding a tab with two tab pages.
We will call one TabGeneral, and the other TabNumberSeq.


5. To add the DefaultLocation field from the CarRentalParameter table, you
simply drag the field from the CarRentalParameter datasource and drop it
onto the TabGeneral tab page.


6. To add all the necessary fields in the TabNumberSeq tab page, simply
copy from one of the other parameter forms and paste it onto the tab page
in the CarRentalParameters form. I have copied the next layout from the
InventParameters form:


7. We now have to add some methods to the form for the setup to
work properly:
public class FormRun extends ObjectRun
{
NumberSeqReference numberSeqReferenceCarRental;
boolean runExecuteDirect;
TmpIdRef tmpIdRef;
}


[ 243 ]
void numberSeqPreInit()
{
runExecuteDirect = false;
// Load the number sequences for the
// specified module.
numberSeqReferenceCarRental =
CarRentalParameters::numberSeqReference();
numberSeqReferenceCarRental.load();
// Set the number sequences into the
// tmp table TmpIdRef
tmpIdRef.setTmpData(NumberSequenceReference::
configurationKeyTableMulti(
[CarRentalParameters::numberSeqModule()]));
}
public void init()
{
this.numberSeqPreInit();
super();
CarRentalParameters::find();
}


We also have to add some code to the following methods in the NumberSeqReference
data source:
void executeQuery()
{
if (runExecuteDirect)
{
super();
}
else
{
runExecuteDirect = true;
this.queryRun(NumberSeqReference::buildQueryRunMulti(
numberSequenceReference,
tmpIdRef,
[CarRentalParameters::numberSeqModule()]));
numbersequenceReference_ds.research();
}
}


void removeFilter()
{
runExecuteDirect = false;
numbersequenceReference_ds.executeQuery();
}



8. Also, remember to add a display menu item for this form and add it to the
CarRental menu. The display menu item should also have the configuration
key that you created earlier in this chapter, so that it looks something like the
next screenshot: