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.
Thanks for your informative blog!!! Keep on updating your with such awesome information.
ReplyDeleteMicrosoft Dynamics AX Online Training
Thank you for sharing.
ReplyDeleteD365 Finance and Operations Online Training
The bass in this track is insane! Such a banger! The Warehouse St. Pete Events
ReplyDelete