Monday, July 23, 2012

Get AX4.0 look and feel back in Ax2009

You all might be aware that all forms in Ax2009 are behaving like independent application forms.i,e When you open any form it will get open outside the application.
So following are the two solutions to open forms in same workspace as in Ax4.0
1. Change the formdesign property windowtype(from standard to workspace).this you have to do for all the forms which is time cosuming.
2. Or else Add following line in the init method of SysSetupFormRun class. before super() as shown in the following code
public void init()
{
//at run-time you are setting property to workspace.
this.form().design().windowType(FormWindowType::Workspace);
super();
SysSecurityFormSetup::loadSecurity(this);
this.dimensionFieldCtrls();
this.inventStorageDimFieldCtrls();
if (this.isWorkflowEnabled())
{
workflowControls = SysWorkflowFormControls::construct(this);
workflowControls.initControls();
}
}

X++ code to hide content pane in ax2009

This is for developers , not for endusers.As you know it will irritate during developemnt since it is appearing on top of all windows when we open form.
static void hideContentPaneWindow(Args _args)
{
#WinApi
HWND contentPane = WinApi::findWindowEx(WinAPI::findWindowEx(infolog.hWnd(),
0, 'MDIClient', ''),0,'ContentFrame','' );
;
if (contentPane)
WinApi::ShowWindow(contentPane,#SW_HIDE); // To restore use #SW_RESTORE
}

How to Use Temporary Table in Form

Temporary table(Table whose property temporary set to "yes") is not persistent media , so at run-time you have to populate the temporary table and attach the same to the form/report. For illustration purpose ,I am using inventTable data and attaching the items whose group is Parts.
Steps
1. Create temporary table as TmpTestTable with 3 fields(ItemId,Itemname,ItemGroup).
2. Create a form as TempTestTable and attach the table as datasource
3. Create a new method on the form and copy the following code
TmpTestTable populateRecords(ItemGroupId _itemGroupId)
{
TmpTestTable tmpTable;
InventTable inventTable;
;
while select inventTable
where inventTable.ItemGroupId == _itemGroupId
{
tmpTable.Itemid = inventTable.ItemId;
tmpTable.ItemName = inventTable.ItemName;
tmpTable.Itemgroup = inventTable.ItemGroupId;
tmpTable.insert();
}
return tmpTable;
}
4. Call the above method in init() after super as below public void init()
{
super();
// Call the setTmpData method to attach records to datasource
TmpTestTable.setTmpData(element.populateRecords("Parts"));
}

How to use Dialog in Dynamics Ax.

If you came accross a requirement , where you need to collect the information and then executes a task . In such scenario Please make use of RunBase class.
Advantage of RunBase class
1. It provides dialog for presenting and collecting the information from user.
2. Pack/Unpack methods , for storing the last value entered by the user.
3. Progress bar ,for long time process where in you can show a progress bar.
4. Validate method , to validate the data entered by the user in the dialog.
you can refer tutorial in AOT->Classes->tutorial_RunBaseForm .

X++ code to identify multiple selected records in Grid

Steps : 1. Create a new method on form and copy the following code. 2. Next create a button on form . and call the method on the button click event. (for the button property makesure the Multiselect should be set to yes , or else by default for multiple selection system will disable the buttons)
void checkSelectedRecords()
{
InventTable inventLocal;
;
//getFirst method gets all the selected records in the grid
inventLocal = InventTable_ds.getFirst(true);
while (inventLocal)
{
info(strfmt("You selected Item %1",inventLocal.ItemId));
// get the next selected record
inventLocal = InventTable_ds.getNext();
}
}

Tuesday, January 17, 2012

How to set Default Order Settings for an Item??

How to set Default Order Settings for an Item??
static void Set_DefaultOrderSettings(Args _args)
{
InventTable inventTable;
InventItemInventSetup invent;
InventItemPurchSetup purch;
InventItemSalesSetup sales;
;
delete_from invent;
delete_from purch;
delete_from sales;

while select inventTable
{
if(!InventItemPurchSetup::findDefault(inventTable.ItemId))
{
InventItemPurchSetup::insertDefault(inventTable.ItemId);
}

if(!InventItemInventSetup::findDefault(inventTable.ItemId))
{
InventItemInventSetup::insertDefault(inventTable.ItemId);
}
if(!InventItemSalesSetup::findDefault(inventTable.ItemId))
{
InventItemSalesSetup::insertDefault(inventTable.ItemId);
}
}
}
If you have deleted the Item master and imported with new items then run this job to automatically insert the default order settings for the all items..
Otherwise system will not allow u to create any item transactions it will give error like"No Item parameter for the item"..
Enjoy DAXing :)-

Tuesday, January 3, 2012

How to extract Date value from a DateTime field?

How to extract Date value from a DateTime field:
static void getDate(Args _args)
{
System.DateTime _dateTime;
Date _date;
PurchTable _purchTable;
;
_purchTable = PurchTable::find("PO000008");
_dateTime = System.DateTime::Parse(dateTime2str(_purchTable.createdDateTime));
_date = _dateTime.get_Date();
info(date2str(_date,-1,-1,-1,-1,-1,-1));
}
OR
static void getDate(Args _args)
{
System.DateTime _dateTime;
Date _date;
PurchTable _purchTable;
InteropPermission intPerm = new InteropPermission(InteropKind::ClrInterop);
;
_purchTable = PurchTable::find("PO000008");
intPerm.assert();
_dateTime = System.DateTime::Parse(dateTime2str(_purchTable.createdDateTime));
_date = _dateTime.get_Date();
CodeAccessPermission::revertAssert();
info(date2str(_date,-1,-1,-1,-1,-1,-1));
}
OR
Simply :)-
Instead of the third and second last lines you could use:
_dateTime = DateTimeUtil::date(_purchTable.createdDateTime); for the same result.