07 December 2017

How To AX7 Dynamics 365 Event handlers and Delegates - How to get the reference parameter value from the method to Event handler method


How to get the control access using event handler in D365 or AX7

CustTable custTable = sender.cursor(); // args.getThis() as CustTable;
FormDataSource custTable_ds = sender.formRun().dataSource("CustTable");
FormRun element = sender.formRun();
FormControl myNewButton = element.design(0).controlName("myControl");
myNewButton.enabled(false);

How to get the reference value from the method to Event handler method: in D365 or AX7

Below example -- _salesLineDataSource refers to the main method variable name to identify.
// Note: IdentifierStr should be the same as the existing method.

salesLineDataSource = args.getArg(identifierStr(_salesLineDataSource));
salesTable = args.getArg(identifierStr(pSalesTable));

===================================

Data entity methods - Event handler in D365 or AX7

DataEntityContextEventArgs contextEventArgs = _eventArgs as DataEntityContextEventArgs;
DataEntityRuntimeContext entityCtx = contextEventArgs.parmEntityContext();
DataEntityDataSourceRuntimeContext dataSourceCtx = contextEventArgs.parmEntityDataSourceContext();

=====================================
How to get the arguments using event handlers in AX7 D365 operation: in D365 or AX7

DataEntityRuntimeContext _entityCtx;
DataEntityDataSourceRuntimeContext _dataSourceCtx;

_entityCtx = args.getArgNum(1);
_dataSourceCtx = args.getArgNum(2);
=====================================

[DataEventHandler(tableStr(HcmAbsenceCodeGroupEntity), DataEventType::MappedEntityToDataSource)]
public static void HcmAbsenceCodeGroupEntity_onMappedEntityToDataSource(Common _sender, DataEventArgs _eventArgs)
{
DataEntityContextEventArgs contextEventArgs = _eventArgs as DataEntityContextEventArgs;
DataEntityRuntimeContext entityCtx = contextEventArgs.parmEntityContext();
DataEntityDataSourceRuntimeContext dataSourceCtx = contextEventArgs.parmEntityDataSourceContext();

if (entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Insert
&& dataSourceCtx.name() == dataEntityDataSourceStr(HcmAbsenceCodeGroupEntity, HRMAbsenceCodeGroup))
{
HcmAbsenceCodeGroupEntity hcmAbsenceCodeGroupEntity = _sender as HcmAbsenceCodeGroupEntity;
HRMAbsenceCodeGroup hrmAbsenceCodeGroup = dataSourceCtx.getBuffer();

HcmAbsenceCodeGroupEntityEventHandler::defaultJobIdentificationId(hcmAbsenceCodeGroupEntity);
hrmAbsenceCodeGroup.JmgJobId = hcmAbsenceCodeGroupEntity.JobIdentification;
}
}

=================

DataEventArgs - event for Clicked and retrieve form DS example


FormRun form = sender.formRun();
FormDataSource CustTable_ds = form.dataSource(formDataSourceStr(CustTable,CustTable)) as FormDataSource; //Form

=====================

using post events in AX7 or D365 to get the parameter using args. using query range value Not enum value. Query building and linking table in query.

[PostHandlerFor(classStr(ProjInvoiceChoose), methodStr(ProjInvoiceChoose, addItemTransSaleRange))]
public static void ProjInvoiceChoose_Post_addItemTransSaleRange(XppPrePostArgs args)
{

QueryBuildDataSource itemSaleDataSource;
QueryBuildDataSource inventTableDataSource;
QueryBuildDataSource projItemTransDataSource;
QueryBuildRange itemQueryBuildRange;

itemSaleDataSource = args.getArg(identifierStr(_itemSaleDataSource));

projItemTransDataSource = itemSaleDataSource.addDataSource(tableNum(ProjItemTrans));
projItemTransDataSource.joinMode(false);
projItemTransDataSource.relations(false);
projItemTransDataSource.addLink(fieldNum(ProjItemTrans,ProjTransId),fieldnum(ProjItemTransSale,ProjTransId));

inventTableDataSource = projItemTransDataSource.addDataSource(tableNum(InventTable));
inventTableDataSource.joinMode(JoinMode::InnerJoin);
inventTableDataSource.relations(false);
inventTableDataSource.addLink(fieldNum(ProjItemTrans,ItemId),fieldnum(InventTable,ItemId));
itemQueryBuildRange = inventTableDataSource.addRange(fieldNum(InventTable,HSORentalGrouping));
itemQueryBuildRange.value(SysQuery::valueNot(3));
}
=========================
Report extension MenuItem and Controller. Below is the example for the Customer base data report.

Step1. Duplicate the report and do the required changes.
Step2. Create an extension for the Report output MenuItem and output object to new report what we create in the step1.

Or
If the output menuItem assigned with controller class.

Step1. Duplicate the report and do the required changes.
Step2. Create an EventHandler or COC for the Controller class - getReportName() method.
Step3. In the event handler method, assign the new report to return in this method.

 public static str getReportName(Args _args)
    {
        str reportName;

        if (_args.menuItemName() == menuitemOutputStr(CustBasedata))
        {
            reportName = ssrsReportStr(CustBasedata, Report);
        }
        else if (_args.menuItemName() == menuitemOutputStr(CustListReport))
        {
            reportName = ssrsReportStr(CustListReport, Report);
        }
        else if (_args.menuItemName() == menuitemOutputStr(smmSalesCustItemStatistics))
        {
            reportName = ssrsReportStr(smmSalesCustItemStatistics, Report);
        }

        return reportName;
    }
class smmReportController_EventHandler
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(classStr(smmReportsController), staticMethodStr(smmReportsController, getReportName))]
    public static void smmReportsController_Post_getReportName(XppPrePostArgs args)
    {
        Str reportName;
        smmReportsController  reportsController = args.getThis();
        Args argsLoc = args.getArg(identifierStr(_args));
        //Args argsLoc = args.getArgNum(1);
        if (argsLoc.menuItemName() == menuitemOutputStr(CustBasedata))
        {
            reportName = ssrsReportStr(CustBasedataTRG, Report);
        }     
        args.setReturnValue(reportName);
    }

}

No comments:

Post a Comment

Give me the commetns and solutions

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->...