Wednesday 29 September 2021

Difference Between Edit And Display Method in Ax

Display Method:

The display method means that the method’s return value is being displayed on a form or a report. This value is fixed and cannot be edited on the form or report. If a user only wants to display the value display method is used.


Edit Method: 

Edit methods are basically the same as display methods. Edit indicates that the method’s return type is to be used to provide information for a field that is used in a form. The value in the field can be altered and that users can also write data to the fields.

Setting default field value in AX

Using table initValue() we can set default values of any table field during creating a new record. This can also be done on a form level so that the value will only be set for the specific form. Here is the example, let's suppose the table is yourTable and fields are currentDate, YourField

public void initValue() { super(); // setting current date time yourTable.currentDate = this.Now();

//setting any default value yourTable.YourField = "Default value";

}

Thursday 9 September 2021

lookupReference method on form data source field in AX / X++

 public Common lookupReference(FormReferenceControl _formReferenceControl)
{
    HcmWorker HcmWorker;
    Query query = new Query();
    QueryBuildRange         queryBuildRange, qbr1;
    QueryBuildDataSource    qbds, qbds1, qbds2, qbds3, qbds4, qbds5;
    SysReferenceTableLookup sysTableLookup;
    qbds = query.addDataSource(tableNum(HcmWorker));
    qbds1 = qbds.addDataSource(tableNum(DirAddressBookPartyView));
    qbds1.addLink(fieldNum(DirAddressBookPartyView,RecId),fieldNum(HcmWorker, Person));
    qbds2= qbds1.addDataSource(tableNum(RetailStoreAddressBook));
                     qbds2.addLink(fieldNum(RetailStoreAddressBook,AddressBook),fieldNum(DirAddressBookPartyView,AddressBook));

    qbds3= qbds2.addDataSource(tableNum(RetailStoreTable));
    qbds3.addLink(fieldNum(RetailStoreTable,RecId),fieldNum(RetailStoreAddressBook,StoreRecId));
    qbds4 =qbds3.addDataSource(tableNum(LedgerJournalName));
    qbds4.addLink(fieldNum(LedgerJournalName, SL_RetailStoreId),fieldNum(RetailStoreTable,StoreNumber));

    sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(HcmWorker), _formReferenceControl, true);
    sysTableLookup.addLookupField(fieldNum(HcmWorker,personnelNumber));
    sysTableLookup.addLookupField(fieldNum(HcmWorker, Person));

    qbr1 = qbds2.addRange(fieldNum(RetailStoreAddressBook,AddressBookType));
    qbr1.value(queryValue(RetailAddressBookType::Employee));

    queryBuildRange = qbds4.addRange(fieldNum(LedgerJournalName,JournalName));
    queryBuildRange.value(queryValue(journalName));

    sysTableLookup.parmQuery(query);

    return sysTableLookup.performFormLookup();
}

Find Current Exchange rate using X++ / Ax

Below is the code to find the current exchange rate of given currencies in X++

static void CurrentExchangeRate(Args _args)
{
    ExchangeRate     exchangeRate;
    ExchangeRateType ExchangeRateType; 
    ExchangeRateCurrencyPair exchangeRateCurrencyPair;
    real             exchRate;
    
    CurrencyCode fromCurrency  = "USD";
    CurrencyCode toCurrency    = "PKR";
    TransDate    transDate     = today();
    
    select firstonly exchangeRateCurrencyPair 
        where 
        exchangeRateCurrencyPair.ExchangeRateType 
        == Ledger::find(Ledger::current()).DefaultExchangeRateType
        &&  exchangeRateCurrencyPair.FromCurrencyCode == fromCurrency 
        &&  exchangeRateCurrencyPair.ToCurrencyCode   == toCurrency;

        exchRate = exchangeRate::findByDate(exchangeRateCurrencyPair.RecId,
            transDate).ExchangeRate;
    
    info(strFmt("Exchange Rate = %1",exchRate/100));
    
}

Send notification/ alert using X++ in Ax 2012

 Here is the X++ code to send the custom notification alert in Ax 2012.

static void SendNotificationAlert(Args _args)
{
    EventInbox  EventInbox,inbox;
    EventInboxData  eventInboxData;
    SysUserInfo SysUserInfo;
    int64 inboxId;
    ;

    ttsBegin;
        select SysUserInfo 
            order by SysUserInfo.Id 
            where SysUserInfo.Id== curUserId();

    { 
        select maxof(inboxId) from inbox;
        inboxId = EventInbox::nextEventId();
        EventInbox.CompanyId              =   curext();
        EventInbox.AlertTableId           =   212;
        EventInbox.AlertCreatedDateTime   =   DateTimeUtil::utcNow();
        EventInbox.ParentTableId          =   212;
        EventInbox.IsRead                 =   NOYES::No;
        EventInbox.Subject                =   "Notification Received ..";
        EventInbox.AlertedFor             =   "Notification Testing .. "; 
        EventInbox.UserId                 =   SysUserInfo.Id;
        EventInbox.ShowPopup              =   NOYES::Yes;
        EventInbox.Visible                =   NOYES::Yes;
        EventInbox.Message                =   'Notification Received ..!!';
        EventInbox.NotificationType       =   EventNotificationType::Information;
        EventInbox.insert();

        eventInboxData.DataType           =  EventInboxDataType::Context;
        eventInboxData.InboxId            =  inboxId;
        eventInboxData.insert();

        info("Notification sent");

    }

    ttsCommit;
}

Wednesday 8 September 2021

Difference between Ax 2012 and D365FO (AX 7)

Microsoft Dynamics 365FO (AX 7) is web-based and there is no separate client.

For development, Microsoft Dynamics 365FO (AX 7) uses Visual Studio (VS) IDE whereas the older version Ax 2012 uses MorphX. 

MorphX


Visual Studio

The other difference is Dynamics 365 for Operations is an introduction to Extensions. This extends the functionality of elements without overriding the existing ones.

The other main difference is the architecture.



Microsoft Dynamics AX 2012 different form styles are available where in Ax 7 Form patterns are introduced which makes development easier.

Another is the Introduction of data entities in Dynamics D365 Finance and Operations 

Access Form Controls In Form pre/post Event Handlers in Dynamics 365 for Operations (AX7)

This blog will explain all possible ways where form control can be accessed in form using event handlers at different form levels. Events on a form are available at the form level, form control level and on the datasources level in Dynamics 365 for Operations (AX7).

We will access the form control in following

  1. Form’s Method pre/post Event Handlers
  2. Form’s  Event Handlers
  3. Form’s DataSource Event Handlers
  4. Form’s Control Event Handlers
  5. Class’s Method Event Handlers

Form Control Access in Form’s Method pre/post Event Handlers

For example, we are using the CustTable form. and using the init method pre-event handler. we are going to access the CustTable_name control in the event handler. Both pre post event contail XppPrePostArgs class parameter. This will provides information about arguments and return values for event handlers. 




In Form’s Event Event Handlers





In Form’s DataSource Event Handlers





Form’s Control Event Handlers





In Class’s Method Event Handlers







Difference Between Edit And Display Method in Ax

Display Method: The display method means that the method’s return value is being displayed on a form or a report.  This value is fixed and c...