Monday 31 March 2014

How to Read/Write an Excel file through X++ code

How to write an Excel file through X++ code

In This Post you will found two code sample
1.Write data in excel through X++ code.
2. Read from an Excel through X++ code

1.Write data in excel through X++ code.

static void thaAxapta_Write2Excel(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);
}


2. Read from an Excel through X++ code

static void theAxapta_ReadExcel(Args _args)
{

SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
ItemId itemid;
Name name;
FileName filename;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = "C:\\item.xls";
try
{
    workbooks.open(filename);
}
catch (Exception::Error)
{
    throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
    row++;
    itemId = cells.item(row, 1).value().bStr();
    name = cells.item(row, 2).value().bStr();
    info(strfmt('%1 - %2', itemId, name));
    type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}

Wednesday 26 March 2014

code to Create a login page for ax clients

Hi,
I would like to share with you how we can create a login page so that everytime a user wants to user the system,he/she must provide use login details and password.
Am going to demonistrate using the ax code below:

Note: The first class which is called during ax startup is Application class and the method in that class is called the Startuppost  method.Copy paste this code in the startuppost method:


 void startupPost()
{

Dialog d;
DialogField df, df1, df2;
userinfo user;
 UserId   userid;



boolean ret;
;
d = new Dialog("Secure User Login Details");


    d.windowType(FormWindowType::PopUp);


  df = d.addField(extendedTypeStr(userid),"UserID");

df1 = d.addField(extendedTypeStr(userid),"UserName");
df2 = d.addField(extendedTypeStr(string30),"Password");




df.value(curuserid());
select user
where user.id == curuserid();
if(user)
{

df1.value(user.name);
}
df1.allowEdit(false);
df1.displayLength(25);

df2.passwordStyle();



while(d.run())

{


if((df2.value()=="" || df2.value() != user.id) )
{

//throw error("wrong password");
    Box::info(strFmt("Wrong password.The system will now shutdown!!!!!"));


infolog.shutDown(true);


//df2.doNull();
//continue;
}
else
{
ret = true;
break;
}
}
if(ret == false)
{
infolog.shutDown(true);

}

Thank you and keep reading for more

Wednesday 19 March 2014

MS Dynamics Architecuter

Hello all, as part of introduction i would like to discuss the architecture of ax system.I will use diagrams to explain.

The ax system uses a 3-tier architecture as shown:


Other components integrate with the ax and gives us the extended architecture as shown:




Thanks and keep reading for more


                                                                                                                                                                                 


Security Keys in Ax

Hi guys,i would like to share with you about security keys in Ax:

Security Keys in Ax

Dynamics Ax provides following keys to provide the security for your application

1.License Keys :

It is the First Level Security , specifies what all features/modules/development tools we can access in the standard product. License Keys will be used after installation to unlock the product. License Keys will be issued by the Microsoft for partners/vendors to develop vertical/generic solutions.


2.Configuration Keys :

It is Second Level Security , To Enable/Disable the object/feature for all the users.


3.Security Keys :

These keys used for enable/disable any object/features to group of users.


4. Record Level security :

Basically it deals with the data , if you want to restrict the viewing of records per user group than we setup record level security.