Thursday, December 29, 2011

How to update 'Modified by' property of Table through code

We often came accross a situation where we need to modify some property value for multiple objects. To expedite this process we do it through job. I also found a similar case. In my situation i was required to update 'Modified by' field of the table to yes so that each table will record the information of which user has modified the record. Here is the simple job for this

TreeNode TreeNode;
TreeNode BaseTreeNode;
UtilEntryLevel UtilEntryLevel;
#AOT
;
BaseTreeNode = TreeNode::findNode(#TablesPath);
TreeNode = BaseTreeNode.AOTfirstChild();

while(TreeNode)
{
treeNode.AOTsetProperty("ModifiedBy", "Yes");
TreeNode.AOTcompile();
TreeNode.AOTsave();
TreeNode=TreeNode.AOTnextSibling();
pause;
}

Saturday, May 7, 2011

How to get On-Hand inventory of past years (by date)

Many a times we come accross a requirement from customer to show on hand inventory of last year or some other report of this type as it is not included in the out of box package. I found a very interesting job from the community web site related to this.

static void findingOnHandByDate(Args _args)
{
ItemId itemId;
InventDim inventDimCriteria;
InventDimParm inventDimParm;
InventSumDateDim inventSumDateDim;
TransDate start, finish;
int c;
int onHandTotal;
;
start = str2date("1/1/2010", 213);
finish = str2date("12/31/2010", 213);
onHandTotal = 0;
while(start != finish)
{
c++;
// Specify the item to get onhand info on
itemId = "00017470";

inventSumDateDim =
InventSumDateDim::newParameters(start,
itemId,
inventDimCriteria,
inventDimParm);

info(strfmt("Date: %1 on hand: %2", start, num2str(inventSumDateDim.postedQty() + inventSumDateDim.receivedQty() - inventSumDateDim.deductedQty(), 0, 2, 1, 1)));
onHandTotal += (inventSumDateDim.postedQty() + inventSumDateDim.receivedQty() - inventSumDateDim.deductedQty());
start += 1;
}
info(strfmt("Avg on hand per year: %1", onHandTotal / 365));
}

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