Saturday, April 30, 2011

Writing data to EXCEL

Here is a simple code to write data in EXCEL from X++

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);
}

Reading Data from EXCEL

Here is a simple code to read data from Excel

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

New, Changed, and Deprecated Features for Microsoft Dynamics AX 2012

I found a very useful document which provides a summary of new and changed features that are planned to be implemented in Microsoft Dynamics AX 2012. Additionally it provides deprecated feature notices for features which are planned to be removed in Microsoft Dynamics AX 2012 or future releases.

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d38bb877-7cf8-400e-8a50-47d4ebbaf4a6&displaylang=en

Furthermore, it is also of the great interest to practice some of new functionalities in the guided hands on labs from the following link

http://blogs.msdn.com/b/ukax/archive/2011/04/15/dynamics-ax-2012-hands-on-labs.aspx

Friday, March 18, 2011

Dynamics AX 2009 Financials Training Videos

I've come accross some training materials related to financials in Dynamics AX 2009. It is shared by one of my friend. Here is the link of those videos

https://cid-1613f1612d4c9e73.office.live.com/viewpermissions.aspx/Public/Financial%20Videos?ref=1

Enjoy daxing :)
Surely, you will find them really worth watching.

Monday, March 7, 2011

How to copy Advance query for other users, that is created by one user

Many a times we came accross an issue. for any report or form, when we make a complex query to display the records we have to enter the same ranges and criterias for all the users.
Here is the code by which you can just copy the query for all the other users. This will copy all advance queries created by from user.

static void advanceFilterQueries(Args _args)
{
SysLastValue sysLastValue;
UserId fromUserId, toUserId;
;

fromUserId = "user1"; // Enter ID of the user from where to copy
toUserId = "user2"; // Enter ID of the user where you want to copy
while select sysLastValue
where sysLastValue.recordType == UtilElementType::UserSetupQuery
&& sysLastValue.UserId == fromUserId
{
sysLastValue.UserId = toUserId;
sysLastValue.RecId = 0;
sysLastValue.insert();
}
}

Saturday, November 27, 2010

To get table value without buffer

Some times in a code we are declaring variables even for non repeated code values. It is possible to get data from the database without declaring any table variables. Some of you might already be awared of this technique. It seems like this:

static void tableValueWithoutDecla(Args _args)
{
// No variables!
;

print (select ProjTable).projID;
pause;
}

Note the parentheses around the select statement. This tells the compiler to create a temporary, anonymous buffer to hold the record. The select statement uses the exact table name and is immediately followed by a field name to get a value from a field.

If you use this there’s no Intellisense to help you look up the field name because the editor doesn’t know the type of the anonymous buffer.

This technique is often used in exist() methods on tables.

Generating and Sending Emails in Dynamics AX

To generate and send emails in dynamics AX we have SysMailer class. I've came accross a very good example and explanation from Brandon George blog. To give an example of how we used this, he added a new enum value to the Sales Status of a sales order called 'Credit Hold'. When a customer is past due, or is over there given credit limit, then the sales order is placed on 'Credit Hold' and a email is sent out to a given list of people (alias group of emails contained on the email server). The people that get this list decided when the sales order can be actually turned from Credit Hold, to Open Order. The automatically generated email is what keeps the flow of this information system controlled, and not being dependant on a user to have to send a email out.

Let's just dive right in and look at the SysMailer example code:


SysMailer mail;
;

mail = new SysMailer();
mail.SMTPRelayServers().add("mail.yoursmtpserver.com");
mail.fromAddress("test@test.com");
mail.tos().add("you@you.com");

// Build the Message
mail.htmlBody(strfmt(""));
mail.subject(strfmt(""));
mail.sendMail();


That's it! Pretty straight forward, and great piece of code that can be very useful when alerting, and sharing of information and events as they occur.