15 December 2017

How to get ledger dimension values for active account structure in AX 2012 AX7 D365

public static DimensionValue dimensionDisplayValue(LedgerDimensionAccount _ledgerDimension, Name _dimensionName )
{
DimensionAttributeLevelValueAllView dimAttrView; //View that will display all values for ledger dimensions
DimensionAttribute dimAttr; //Main dimension attribute table


select DisplayValue from dimAttrView
where dimAttrView.ValueCombinationRecId == _ledgerDimension //generalJournalAccountEntry.LedgerDimension
join BackingEntityType from dimAttr
where dimAttr.RecId == dimAttrView.DimensionAttribute
&& dimAttr.Name == _dimensionName; // Dimension field name

return dimAttrView.DisplayValue;
}

11 December 2017

AX 7 Dynamics 365 operations display methods

[ExtensionOf(tableStr(LedgerEntryJournal))] // this refers to table extension
final class TTLLedgerEntryJournal_Extension // class name must post with _Extension
{

[SysClientCacheDataMethodAttribute(true)]
public static display Name journalName(LedgerEntryJournal _this)
{
return LedgerJournalTable::find(_this.JournalNumber).JournalName;
}

[SysClientCacheDataMethodAttribute(true)]
public static display Name journalDescription(LedgerEntryJournal _this)
{
return LedgerJournalTable::find(_this.JournalNumber).Name;
}

}

==========

[ExtensionOf(tableStr(LedgerEntryJournal))] // this refers to table extension
public static class TTLLedgerEntryJournal_Extension // class name must post with _Extension
{

[SysClientCacheDataMethodAttribute(true)]
public static display Name journalName(LedgerEntryJournal _this)
{
LedgerEntryJournal:: // can call the static methods what we defined in the current class/Table
return LedgerJournalTable::find(_this.JournalNumber).JournalName;
}

[SysClientCacheDataMethodAttribute(true)]
public static display Name journalDescription(LedgerEntryJournal _this)
{
return LedgerJournalTable::find(_this.JournalNumber).Name;
}

}

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

}

05 December 2017

How to: Disable or Enable an Action Pane Button in D365 - AX7 - Dynamics 365 operations

The below example is for using Event handlers - salesTableInteration is the base class.
class TESTSalesTableInteraction
{
[PostHandlerFor(classStr(SalesTableInteraction), methodStr(SalesTableInteraction, enableHeaderUpdateJournalActions))]
public static void SalesTableInteraction_Post_enableHeaderUpdateJournalActions(XppPrePostArgs args)
{
Page page;
SalesTableInteraction salesTableIntraction = args.getThis() as SalesTableInteraction;
page = salesTableIntraction.page();
page.actionPaneControlEnabled(formControlStr(SalesTable, buttonCreatePurchOrder), true);
}

}

AX7 / D365 Extensions: Extend the validateField Method on a Table

Click here

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