This blog is for Dynamics AX (AXAPTA) Developers,this will help you for your development issues. This site contains some Microsoft Dynamics AX X++ Codes for use in your day to day use.
26 June 2017
21 June 2017
Event Handlers in Dynamics AX 7 and Dynamics AX 365 - D365
If you want to create a new event handler then have to create a class and define.
Example:
How to get formRun or element in the event handler in D365
[PostHandlerFor(formStr(AssetTrans), formMethodStr(AssetTrans, init))]
public static void AssetTrans_Post_init(XppPrePostArgs args)
{
FormRun formRunElement;
FormDataSource formDataSource;
CustomTableFixedAssetProfileTmp assetProfileTmp;
QueryBuildDataSource dataSource;
formRunElement = args.getThis();
if( formRunElement.args().callerName() == formStr(HHD_FixedAssetProfile))
{
assetProfileTmp = formRunElement.args().record();// formRun calles the args which is contains the record of caller form
formDataSource = formRunElement.dataSource();
dataSource = formDataSource.query().dataSourceTable(tableNum(AssetTrans));
dataSource.addRange(fieldNum(AssetTrans,BookId)).value(assetProfileTmp.BookId);
dataSource.addRange(fieldNum(AssetTrans,AssetId)).value(assetProfileTmp.AssetId);
}
}
class VendTableHandler
{
[PostHandlerFor(tableStr(VendTable), tableMethodStr(VendTable, insert))] // Post even Handler
public static void VendTable_Post_insert(XppPrePostArgs _args)
{
VendTable vendTable = _args.getThis();
_args.setReturnValue(VendTable::exists(vendTable.AccountNum));
}
}
// For Pre event handler
// [PreHandlerFor(tableStr(VendTable), tableMethodStr(VendTable, insert))]
Note: once you created an event handler for a table method. You can see + symbol for the method left side.
Example:
How to get formRun or element in the event handler in D365
[PostHandlerFor(formStr(AssetTrans), formMethodStr(AssetTrans, init))]
public static void AssetTrans_Post_init(XppPrePostArgs args)
{
FormRun formRunElement;
FormDataSource formDataSource;
CustomTableFixedAssetProfileTmp assetProfileTmp;
QueryBuildDataSource dataSource;
formRunElement = args.getThis();
if( formRunElement.args().callerName() == formStr(HHD_FixedAssetProfile))
{
assetProfileTmp = formRunElement.args().record();// formRun calles the args which is contains the record of caller form
formDataSource = formRunElement.dataSource();
dataSource = formDataSource.query().dataSourceTable(tableNum(AssetTrans));
dataSource.addRange(fieldNum(AssetTrans,BookId)).value(assetProfileTmp.BookId);
dataSource.addRange(fieldNum(AssetTrans,AssetId)).value(assetProfileTmp.AssetId);
}
}
class VendTableHandler
{
[PostHandlerFor(tableStr(VendTable), tableMethodStr(VendTable, insert))] // Post even Handler
public static void VendTable_Post_insert(XppPrePostArgs _args)
{
VendTable vendTable = _args.getThis();
_args.setReturnValue(VendTable::exists(vendTable.AccountNum));
}
}
// For Pre event handler
// [PreHandlerFor(tableStr(VendTable), tableMethodStr(VendTable, insert))]
Note: once you created an event handler for a table method. You can see + symbol for the method left side.
Subscribe to:
Posts (Atom)
Ledger Voucher creation Framework and x++ code to create ledger voucher
Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension-...
-
{ "Message" : "Please verify that the user is valid and set up correctly." } Sol: System Administration > Se...
-
Please click here to access Custom Workflow step by step process:
-
FormRun formRun = sender.formRun(); Object inventTrans_ds = formRun.dataSource(formDataSourceStr(InventMarking,InventTransO...